summaryrefslogtreecommitdiffstats
path: root/client/bug.py
blob: a5c3814ba59921d0f8095e8c7ee5c36b6c9a2b37 (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
58
59
60
61
#!../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
import sys

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:
				sys.exit("'{}' is not a bug.py command. See 'bug help'.".format(args['<args>'][0]))

	elif args['<command>'] in commands:
		if not args['--uri']:
			sys.exit("URI missing")

		bug_mod = import_module('bug_{}'.format(args['<command>']))

		arg = {'--uri': args['--uri']}
		arg.update(docopt(bug_mod.__doc__,
		           argv=[args['<command>']] + args['<args>']))

		bug_mod.entrypoint(arg)

	else:
		sys.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()