Completed
Push — master ( 0f3e04...1c5edf )
by Thomas
30:23 queued 15:11
created

exabgp.application.environ.setargs()   A

Complexity

Conditions 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
# encoding: utf-8
2
3
"""exabgp environement values"""
4
5
import sys
6
import argparse
7
8
from exabgp.environment import Env
9
10
11
def setargs(sub):
12
    # fmt: off
13
    sub.add_argument('-d', '--diff', help='show only the different from the defaults', action='store_true')
14
    sub.add_argument('-e', '--env', help='display using environment (not ini)', action='store_true')
15
    # fmt: on
16
17
18
def default():
19
    sys.stdout.write('\nEnvironment values are:\n')
20
    sys.stdout.write('\n'.join('    %s' % _ for _ in Env.default()))
21
    sys.stdout.flush()
22
23
24
def cmdline(cmdarg):
25
    dispatch = {
26
        True: Env.iter_env,
27
        False: Env.iter_ini,
28
    }
29
30
    for line in dispatch[cmdarg.env](cmdarg.diff):
31
        sys.stdout.write('%s\n' % line)
32
        sys.stdout.flush()
33
34
35
def main():
36
    parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__)
37
    setargs(parser)
38
    cmdline(parser.parse_args())
39
40
41
if __name__ == '__main__':
42
    main()
43