MCPcopy Create free account
hub / github.com/canonical/cloud-init / get_parser

Function get_parser

cloudinit/cmd/cloud_id.py:19–58  ·  view source on GitHub ↗

Build or extend an arg parser for the cloud-id utility. @param parser: Optional existing ArgumentParser instance representing the query subcommand which will be extended to support the args of this utility. @returns: ArgumentParser with proper argument configuration.

(parser=None)

Source from the content-addressed store, hash-verified

17
18
19def get_parser(parser=None):
20 """Build or extend an arg parser for the cloud-id utility.
21
22 @param parser: Optional existing ArgumentParser instance representing the
23 query subcommand which will be extended to support the args of
24 this utility.
25
26 @returns: ArgumentParser with proper argument configuration.
27 """
28 default_instance_json = read_cfg_paths().get_runpath("instance_data")
29 if not parser:
30 parser = argparse.ArgumentParser(
31 prog=NAME,
32 description="Report the canonical cloud-id for this instance",
33 )
34 parser.add_argument(
35 "-j",
36 "--json",
37 action="store_true",
38 default=False,
39 help="Report all standardized cloud-id information as json.",
40 )
41 parser.add_argument(
42 "-l",
43 "--long",
44 action="store_true",
45 default=False,
46 help="Report extended cloud-id information as tab-delimited string.",
47 )
48 parser.add_argument(
49 "-i",
50 "--instance-data",
51 type=str,
52 default=default_instance_json,
53 help=(
54 "Path to instance-data.json file. "
55 f"Default is {default_instance_json}"
56 ),
57 )
58 return parser
59
60
61def handle_args(name, args):

Callers 1

mainFunction · 0.70

Calls 2

read_cfg_pathsFunction · 0.90
get_runpathMethod · 0.80

Tested by

no test coverage detected