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

exabgp.application.environ   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

4 Functions

Rating   Name   Duplication   Size   Complexity  
A cmdline() 0 9 2
A default() 0 4 1
A main() 0 4 1
A setargs() 0 4 1
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