Package: argopt
doc toargparsedriven bydocoptDefine your command line interface (CLI) from a docstring (rather than the
other way around). Because it’s easy. It’s quick. Painless. Then focus on
what’s actually important - using the arguments in the rest of your program.The problem is that this is not always flexible. Still need all the features ofargparse? Now have the best of both worlds… all the extension such asshtaborGooeybut with the simple syntax ofdocopt.Table of contentsInstallationLatest PyPI stable releaseLatest development release on GitHubLatest Conda releaseChangelogUsageAdvanced usage and examplesDocumentationContributionsLICENCEAuthorsInstallationLatest PyPI stable releasepipinstallargoptLatest development release on GitHubPull and install:pipinstall"git+https://github.com/casperdcl/argopt.git@master#egg=argopt"Latest Conda releasecondainstall-cconda-forgeargoptChangelogThe list of all changes is available on the Releases page:.UsageStandarddocoptdocstring syntax applies.
Additionally, some improvements and enhancements are supported, such as type
checking and default positional arguments.'''Example programme description.
You should be able to do
    args = argopt(__doc__).parse_args()
instead of
    args = docopt(__doc__)

Usage:
    test.py [options] <x> [<y>...]

Arguments:
    <x>                   A file.
    --anarg=<a>           Description here [default: 1e3:int].
    -p PAT, --patts PAT   Or [default: None:file].
    --bar=<b>             Another [default: something] should
                          auto-wrap something in quotes and assume str.
    -f, --force           Force.
'''fromargoptimportargopt__version__="0.1.2-3.4"parser=argopt(__doc__,version=__version__)args=parser.parse_args()ifargs.force:print(args)else:print(args.x)For comparison, thedocoptequivalent would be:'''Example programme description.

Usage:
    test.py [options] <x> [<y>...]

Arguments:
    <x>                   A file.
    --anarg=<a>           int, Description here [default: 1e3].
    -p PAT, --patts PAT   file, Or (default: None).
    --bar=<b>             str, Another [default: something] should
                          assume str like everything else.
    -f, --force           Force.
    -h, --help            Show this help message and exit.
    -v, --version         Show program's version number and exit.

'''fromdocoptimportdocopt__version__="0.1.2-3.4"args=docopt(__doc__,version=__version__)args["--anarg"]=int(eval(args["--anarg"]))ifargs["--patts"]:args["--patts"]=open(args["--patts"])ifargs["--force"]:print(args)else:print(args["<x>"])Advanced usage and examplesSee theexamplesfolder.Documentationdefargopt(doc='',argparser=ArgumentParser,formatter_class=RawDescriptionHelpFormatter,logLevel=logging.NOTSET,**_kwargs):"""
  Note that `docopt` supports neither type specifiers nor default
  positional arguments. We support both here.

  Parameters
  ----------
  doc  : docopt compatible, with optional type specifiers
      [default: '':str]
  argparser  : Argument parser class [default: argparse.ArgumentParser]
  version  : Version string [default: None:str]
  formatter_class  : [default: argparse.RawDescriptionHelpFormatter]
  logLevel  : [default: logging.NOTSET]
  _kwargs  : any `argparser` initialiser arguments
      N.B.: `prog`, `description`, and `epilog` are automatically
      inferred if not `None`

  Returns
  -------
  out  : argparser object (default: argparse.ArgumentParser)

  Usage
  -----
  Extension syntax example: [default: 1e3:int].

  You should be able to do
      parser = argopt(__doc__)
      args   = parser.parse_args()
  instead of
      args = docopt(__doc__)

  TODO
  ----
  add_argument_group
  add_mutually_exclusive_group
  (better) subparser support
  (docopt extension) action choices
  (docopt extension) action count
  """ContributionsAll source code is hosted onGitHub.
Contributions are welcome.LICENCEOpen Source (OSI approved):AuthorsCasper da Costa-Luis (casperdcl)We are grateful for all.