3

I have utility scripts for interfacing with Auth0. I want to combine them into a single tool similar to gcloud and awscli:

$ gcloud [module] [commands & args]
$ aws cloudformation validate-template --template-body file://test.yml

$ auth0 user add --email [EMAIL] ...
$ auth0 connection backup --connection [CXD_ID]
$ auth0 [user | connection | client | ...]

I don't think I can do this with argparse as it treats args w/o the leading dash(es) as mandatory positional args, but I am certainly not an expert.

drumboots
  • 391
  • 2
  • 3
  • 11
  • 1
    Maybe subcommands? https://docs.python.org/3/library/argparse.html#sub-commands – G_M Mar 12 '18 at 20:14
  • That's it. Or I think that's it. In all my searching I never thought to search for "sub commands". Thanks! – drumboots Mar 12 '18 at 20:24
  • 1
    No problem. I'm not sure if third-party is an option but if so, you might want to look into click too: http://click.pocoo.org/6/commands/ – G_M Mar 12 '18 at 20:25
  • From your sample it's not entirely clear which strings are keys (or flags) with-or-without the prefix, and which are names for strings. – hpaulj Mar 13 '18 at 02:46

1 Answers1

0

@delirious-lettuce provided the answer: sub-commands in argparse. Lesson learned: Read all the documentation before posting to SO.

Related:

https://docs.python.org/3/library/argparse.html#sub-commands

How to parse multiple nested sub-commands using python argparse?

drumboots
  • 391
  • 2
  • 3
  • 11