| #!/usr/bin/env python |
| # -*- python -*- |
| import optparse, sys |
| import stgit.main |
| from stgit import argparse, commands, completion |
| |
| def main(): |
| op = optparse.OptionParser() |
| op.add_option('--asciidoc', metavar = 'CMD', |
| help = 'Print asciidoc documentation for a command') |
| op.add_option('--commands', action = 'store_true', |
| help = 'Print list of all stg subcommands') |
| op.add_option('--cmd-list', action = 'store_true', |
| help = 'Print asciidoc command list') |
| op.add_option('--py-cmd-list', action = 'store_true', |
| help = 'Write Python command list') |
| op.add_option('--bash-completion', action = 'store_true', |
| help = 'Write bash completion code') |
| options, args = op.parse_args() |
| if args: |
| op.error('Wrong number of arguments') |
| if options.asciidoc: |
| argparse.write_asciidoc(stgit.main.commands[options.asciidoc], |
| sys.stdout) |
| elif options.commands: |
| for cmd in sorted(commands.get_commands( |
| allow_cached = False).iterkeys()): |
| print cmd |
| elif options.cmd_list: |
| commands.asciidoc_command_list( |
| commands.get_commands(allow_cached = False), sys.stdout) |
| elif options.py_cmd_list: |
| commands.py_commands(commands.get_commands(allow_cached = False), |
| sys.stdout) |
| elif options.bash_completion: |
| completion.write_completion(sys.stdout) |
| else: |
| op.error('No command') |
| |
| if __name__ == '__main__': |
| main() |