Executes the command in the provider
(providers, parser, args)
| 55 | |
| 56 | |
| 57 | def execute_command(providers, parser, args): |
| 58 | """ Executes the command in the provider """ |
| 59 | |
| 60 | # Switch - for _ in command names. We use - in the CLI syntax for ease of |
| 61 | # use, but we need an _ in Python function names |
| 62 | if 'command' in args and args.command is not None: |
| 63 | args.command = args.command.replace('-', '_') |
| 64 | |
| 65 | # Figure out what provider the command was for (if any) and call the |
| 66 | # relevant function. If we don't get a match, print the help |
| 67 | if args.provider in providers and \ |
| 68 | 'command' in args and \ |
| 69 | args.command is not None: |
| 70 | command = providers[args.provider].commands()[args.command] |
| 71 | command(args) |
| 72 | else: |
| 73 | # If no provider has been given, display the top level help, |
| 74 | # otherwise, call the help() method in the provider |
| 75 | if args.provider is None: |
| 76 | parser.print_help() |
| 77 | else: |
| 78 | command = providers[args.provider].commands()['help'] |
| 79 | command() |
| 80 | |
| 81 | |
| 82 | def main(): |