aboutsummaryrefslogtreecommitdiffstats
path: root/stg-build
blob: c13587381c4fd9bd2fa75ff889af8d956db47bea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python2
# -*- 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()