dnslink.__main__.main()   A
last analyzed

Complexity

Conditions 3

Size

Total Lines 26
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 18
nop 0
dl 0
loc 26
ccs 11
cts 11
cp 1
crap 3
rs 9.5
c 0
b 0
f 0
1
"""Command line program for DNSLink protocol."""
2
3 1
import argparse
4 1
import sys
5
6 1
from . import resolve
7
8
9 1
def handle_resolve(args):
10
    """Handle resolve."""
11
12 1
    for protocol in resolve(args.domain, args.protocol, args.depth):
13 1
        print(protocol)
14
15
16 1
def main():
17
    """Handle command line program."""
18
19 1
    parser = argparse.ArgumentParser(
20
        prog=__package__,
21
        description='Python implementation of DNSLink protocol'
22
    )
23 1
    subparsers = parser.add_subparsers()
24
25 1
    resolve_parser = subparsers.add_parser(
26
        name='resolve',
27
        help='resolve a DNSLink record'
28
    )
29 1
    resolve_parser.set_defaults(which='resolve')
30 1
    resolve_parser.add_argument('domain', help='a domain to resolve')
31 1
    resolve_parser.add_argument('--protocol', help='a record protocol', type=str, default=None)
32 1
    resolve_parser.add_argument('--depth', help='a recursion depth', type=int, default=16)
33
34
    if len(sys.argv) == 1: # pragma: no cover
35
        parser.print_help(sys.stderr)
36
        sys.exit(1)
37
38 1
    args = parser.parse_args()
39
40 1
    if args.which == 'resolve':
41 1
        handle_resolve(args)
42
43
44
if __name__ == '__main__': # pragma: no cover
45
    main()
46