Completed
Push — master ( 3c108b...266306 )
by Oleksandr
03:35
created

verboselib.cli.main.make_parser()   A

Complexity

Conditions 1

Size

Total Lines 36
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 36
rs 9.28
c 0
b 0
f 0
cc 1
nop 0
1
import argparse
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
import functools
3
4
from verboselib.version import VERSION
5
6
from .utils import print_out
7
8
from .command_compile import CompileCommand
9
from .command_extract import ExtractCommand
10
11
12
def show_version() -> None:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
13
  print_out(f"verboselib {VERSION}")
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
14
15
16
def make_parser() -> argparse.Namespace:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
17
  parser = argparse.ArgumentParser(
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
18
    description="run a verboselib command",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
19
    add_help=True,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
20
  )
21
  parser.add_argument(
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
22
    "-V", "--version",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
23
    dest="show_version",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
24
    action="store_true",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
25
    help="show version of verboselib and exit"
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
26
  )
27
28
  subparsers = parser.add_subparsers(
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
29
    title="subcommands",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
30
    dest="command_name",
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
31
  )
32
33
  extract_cmd_parser = ExtractCommand.make_parser(
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
34
    factory=functools.partial(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
35
      subparsers.add_parser,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
36
      name=ExtractCommand.name,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
37
      aliases=ExtractCommand.aliases,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
38
    ),
39
  )
40
  extract_cmd_parser.set_defaults(executor_factory=ExtractCommand.make_executor)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
41
42
  compile_cmd_parser = CompileCommand.make_parser(
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
43
    factory=functools.partial(
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
44
      subparsers.add_parser,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
45
      name=CompileCommand.name,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
46
      aliases=CompileCommand.aliases,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation (add 2 spaces).
Loading history...
47
    ),
48
  )
49
  compile_cmd_parser.set_defaults(executor_factory=CompileCommand.make_executor)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
50
51
  return parser
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
52
53
54
def main():
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
55
  parser = make_parser()
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
56
  args = parser.parse_args()
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
57
58
  if args.show_version:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
59
    show_version()
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
60
    return
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
61
62
  if hasattr(args, "executor_factory"):
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
63
    executor = args.executor_factory(args)
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
64
    executor()
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
65
  else:
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 4 spaces were expected, but 2 were found.
Loading history...
66
    parser.print_help()
0 ignored issues
show
Coding Style introduced by
The indentation here looks off. 8 spaces were expected, but 4 were found.
Loading history...
67