-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli1.py
More file actions
63 lines (51 loc) · 1.44 KB
/
cli1.py
File metadata and controls
63 lines (51 loc) · 1.44 KB
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
62
63
import click
import click_completion
import os
click_completion.init()
option_type = click.Choice('obj1 obj2 obj3'.split())
@click.group()
def cli():
"""My Cool Tool"""
@cli.group(name='object')
def object_group():
"""Object subcommand"""
@object_group.command()
@click.argument('option', type=option_type)
def get(option):
click.echo('option: {}'.format(option))
commands = (
('"" object get ""', 1),
('"" object get ""', 2),
('"" object get ""', 3),
'object get obj1',
'--help',
'object --help',
'object get --help',
)
os.environ['BASH_COMP'] = 'complete'
import sys, time
time.sleep(1)
print('Click Version: {}'.format(click.__version__))
print('Click Completion Version: {}'.format(click_completion.__version__))
print('Python Version: {}'.format(sys.version))
for cmd in commands:
try:
time.sleep(0.1)
print('\n-----------')
print('> ' + str(cmd))
time.sleep(0.1)
if len(cmd) == 2:
os.environ['COMP_WORDS'] = cmd[0]
os.environ['COMP_CWORD'] = str(cmd[1])
cli(complete_var='BASH_COMP')
else:
try:
del os.environ['COMP_WORDS']
del os.environ['COMP_CWORD']
except:
pass
cli(cmd.split())
except BaseException as exc:
if str(exc) != '0' and \
not isinstance(exc, (click.ClickException, SystemExit)):
raise