Skip to main content
added 170 characters in body
Source Link
mgilson
  • 312k
  • 70
  • 656
  • 722

This seems like you want to use subparsers.

from argparse import ArgumentParser parser = ArgumentParser()   subparsers = parser.add_subparsers() install = subparsers.add_parser('install') install.add_argument('-b') install.add_argument('-a') install.set_defaults(subparser='install') lst = subparsers.add_parser('list') lst.set_defaults(subparser='list')   update = subparsers.add_parser('update') update.set_defaults(subparser='update') print parser.parse_args() 

As stated in the docs, this can beI have combined with set_defaults in interesting waysso that you can know which subparser was invoked.

This seems like you want to use subparsers.

from argparse import ArgumentParser parser = ArgumentParser()   subparsers = parser.add_subparsers() install = subparsers.add_parser('install') install.add_argument('-b') install.add_argument('-a') lst = subparsers.add_parser('list') update = subparsers.add_parser('update') print parser.parse_args() 

As stated in the docs, this can be combined with set_defaults in interesting ways.

This seems like you want to use subparsers.

from argparse import ArgumentParser parser = ArgumentParser() subparsers = parser.add_subparsers() install = subparsers.add_parser('install') install.add_argument('-b') install.add_argument('-a') install.set_defaults(subparser='install') lst = subparsers.add_parser('list') lst.set_defaults(subparser='list')   update = subparsers.add_parser('update') update.set_defaults(subparser='update') print parser.parse_args() 

As stated in the docs, I have combined with set_defaults so that you can know which subparser was invoked.

Source Link
mgilson
  • 312k
  • 70
  • 656
  • 722

This seems like you want to use subparsers.

from argparse import ArgumentParser parser = ArgumentParser() subparsers = parser.add_subparsers() install = subparsers.add_parser('install') install.add_argument('-b') install.add_argument('-a') lst = subparsers.add_parser('list') update = subparsers.add_parser('update') print parser.parse_args() 

As stated in the docs, this can be combined with set_defaults in interesting ways.