blob: f1a81471679d1151873148b82cbbcd0807935328 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
"""Command line parsing."""
from __future__ import annotations
import argparse
import os
import sys
import typing as t
from .argparsing import (
CompositeActionCompletionFinder,
)
from .commands import (
do_commands,
)
from .compat import (
HostSettings,
convert_legacy_args,
)
def parse_args(argv=None): # type: (t.Optional[t.List[str]]) -> argparse.Namespace
"""Parse command line arguments."""
completer = CompositeActionCompletionFinder()
if completer.enabled:
epilog = 'Tab completion available using the "argcomplete" python package.'
else:
epilog = 'Install the "argcomplete" python package to enable tab completion.'
parser = argparse.ArgumentParser(prog='ansible-test', epilog=epilog)
do_commands(parser, completer)
completer(
parser,
always_complete_options=False,
)
if argv is None:
argv = sys.argv[1:]
else:
argv = argv[1:]
args = parser.parse_args(argv)
if args.explain and not args.verbosity:
args.verbosity = 1
if args.no_environment:
pass
elif args.host_path:
args.host_settings = HostSettings.deserialize(os.path.join(args.host_path, 'settings.dat'))
else:
args.host_settings = convert_legacy_args(argv, args, args.target_mode)
args.host_settings.apply_defaults()
return args
|