summaryrefslogtreecommitdiffstats
path: root/client/bug.py
blob: ff7958f0eb4eb0d6eafbd4108aea77d7558689b2 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!../flask/bin/python
"""
usage: bug [options] <command> [<args>...]

options:
  -u, --uri ENDPOINT  Project API endpoint
  -h, --help          Print this help text
  -v, --version       Print the client version

commands:
  open        Open a new ticket
  list        List all open bugs in the project
  show        Show a specific ticket by ID

  [Not implemented yet:]
  edit        Edit a ticket
  reopen      Reopen a previously closed ticket
  close       Close a ticket
  lock        Lock a ticket, preventing new comments
  label       Apply a label to a ticket

See 'bug help <command>' for more information on a specific command
"""
from importlib import import_module
from subprocess import call
from docopt import docopt

commands = ['open', 'delete', 'show', 'list', 'edit']
def main():

	if args['<command>'] in ['help', None]:
		if not args['<args>']:
			print(__doc__.lstrip().rstrip())
		else:
			if args['<args>'][0] in commands:
				bug_mod = import_module('bug_{}'.format(args['<args>'][0]))
				print(bug_mod.__doc__.lstrip().rstrip())
			else:
				exit("'{}' is not a bug.py command. See 'bug help'.".format(args['<args>'][0]))
	elif args['<command>'] in commands:
		if not args['--uri']:
			exit("URI missing")

		bug_mod = import_module('bug_{}'.format(args['<command>']))
		argv = [args['<command>']] + args['<args>']
		arguments = args.copy()
		arguments.update(docopt(bug_mod.__doc__, argv=argv))
		bug_mod.call(arguments)
	else:
		exit("'{}' is not a bug.py command. See 'bug help'.".format(args['<command>']))

if __name__ == '__main__':
	args = docopt(__doc__,
	              version='tbt client version 0.0.0.alpha',
	              options_first=True)
	#print(args)
	main()