Passed
Push — master ( ec8b58...774f6d )
by Velizar
02:44
created

uom.cmd_line.cmd_base_unit()   A

Complexity

Conditions 3

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0052

Importance

Changes 0
Metric Value
eloc 13
dl 0
loc 22
ccs 11
cts 12
cp 0.9167
rs 9.75
c 0
b 0
f 0
cc 3
nop 1
crap 3.0052
1
"""Command line option."""
2 1
from __future__ import absolute_import
3
4 1
from argparse import ArgumentParser
5
6 1
from .uom import base_unit, convert
7
8
9 1
def cmd_convert(arg=None):
10
    """Convert value."""
11 1
    parser = ArgumentParser(prog='uom_convert_value')
12
13 1
    parser.add_argument('value', type=float, nargs='+',
14
                        help='value to be converted')
15
16 1
    parser.add_argument('-s', dest='source', help='unit source')
17
18 1
    parser.add_argument('-t', dest='target', help='unit target')
19
20 1
    parser.add_argument('-v', dest='verbose', action='store_true',
21
                        help='verbose')
22
23 1
    if arg is not None:
24 1
        args = parser.parse_args(arg.split())
25
    else:
26
        args = parser.parse_args()
27
28 1
    print(args)
29
30 1
    if len(args.value) == 1:
31 1
        out = convert(args.value[0], args.source, args.target, args.verbose)
32
    else:
33 1
        out = convert(args.value, args.source, args.target, args.verbose)
34
35 1
    if args.verbose:
36 1
        print(f'Output: {out}')
37
38 1
    return out
39
40
41 1
def cmd_base_unit(arg=None):
42
    """Base unit."""
43 1
    parser = ArgumentParser(prog='uom_base_unit')
44
45 1
    parser.add_argument('unit', help='input unit')
46
47 1
    parser.add_argument('-v', dest='verbose', action='store_true',
48
                        help='verbose')
49
50 1
    if arg is not None:
51 1
        args = parser.parse_args(arg.split())
52
    else:
53
        args = parser.parse_args()
54
55 1
    print(args)
56
57 1
    out = base_unit(args.unit, args.verbose)
58
59 1
    if args.verbose:
60 1
        print(f'Output: {out}')
61
62
    return out
63