Repository navigation
Expand file tree
/
Copy path_cli_config.py
More file actions
55 lines (49 loc) · 2.03 KB
/
Copy path_cli_config.py
File metadata and controls
55 lines (49 loc) · 2.03 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
def parse_args(argv=None):
from argparse import ArgumentParser
from .config import config_items
import textwrap
def wrap(t,w=59):
return textwrap.fill( ' '.join(t.split()), width=w )
parser = ArgumentParser(
description
='Provide basic information about KDSource installation'
)
parser.add_argument('-v','--version',action='store_true',
help=wrap("""Show the KDSource version number and
exit."""))
parser.add_argument('-i','--intversion',action='store_true',
help=wrap("""Show KDSource version encoded into
single integral number (e.g. v1.2.3 is 1002003) and
exit."""))
parser.add_argument('-s','--summary',action='store_true',
help=wrap("""Print summary information about
installation and exit. This displays all the
information that is otherwise available via the --show
flag."""))
parser.add_argument("--show",metavar="ITEM", choices=['list']+config_items,
help=wrap("""Print value of the requested information
ITEM for the current NCrystal installation and exit. Run
with "--show list" to get a list of available ITEM
values."""))
return parser.parse_args(argv)
def main(argv=None):
from .config import summary, config, config_items
args = parse_args(argv)
if args.version:
print(config('version'))
elif args.intversion:
print(config('intversion'))
elif args.summary:
summary()
elif args.show:
if args.show == 'list':
for c in sorted(config_items):
print(c)
elif args.show not in config_items:
raise SystemExit('ERROR: Unknown configuration item "%s"'%args.show)
else:
print(config(args.show))
else:
summary()
if __name__ == '__main__':
main()