Debian Codegraph @

examples/git/git.py

raw
1 #! /usr/bin/env python
2 """
3 usage: git [--version] [--exec-path=<path>] [--html-path]
4 [-p|--paginate|--no-pager] [--no-replace-objects]
5 [--bare] [--git-dir=<path>] [--work-tree=<path>]
6 [-c name=value]
7 <command> [<args>...]
8 git [--help]
9
10 The most commonly used git commands are:
11 add Add file contents to the index
12 branch List, create, or delete branches
13 checkout Checkout a branch or paths to the working tree
14 clone Clone a repository into a new directory
15 commit Record changes to the repository
16 push Update remote refs along with associated objects
17 remote Manage set of tracked repositories
18
19 See 'git help <command>' for more information on a specific command.
20
21 """
22 from subprocess import call
23
24 from docopt import docopt
25
26
27 if __name__ == '__main__':
28
29 args = docopt(__doc__,
30 version='git version 1.7.4.4',
31 options_first=True)
32
33 argv = [args['<command>']] + args['<args>']
34 if args['<command>'] == 'add':
35 # In case subcommand is implemented as python module:
36 import git_add
37 print(docopt(git_add.__doc__, argv=argv))
38 elif args['<command>'] == 'branch':
39 # In case subcommand is a script in some other programming language:
40 exit(call(['python', 'git_branch.py'] + argv))
41 elif args['<command>'] in 'checkout clone commit push remote'.split():
42 # For the rest we'll just keep DRY:
43 exit(call(['python', 'git_%s.py' % args['<command>']] + argv))
44 elif args['<command>'] in ['help', None]:
45 exit(call(['python', 'git.py', '--help']))
46 else:
47 exit("%r is not a git.py command. See 'git help'." % args['<command>'])