edq.config.cmd.list

List the current configuration options.

 1"""
 2List the current configuration options.
 3"""
 4
 5import argparse
 6
 7import edq.config.source
 8
 9CONFIG_FIELD_SEPARATOR: str = "\t"
10
11def run(args: argparse.Namespace) -> int:
12    """ Run the target command and return the suggested exit status. """
13
14    config_info = args._config_info
15
16    rows = []
17    for (key, value) in config_info.raw_config.items():
18        if ((not args.include_cli) and isinstance(args._config_info.sources[key][0].spec, edq.config.source.CLIImplicitSpec)):
19            continue
20
21        row = [key, str(value)]
22        if (args.show_origin):
23            row.append(str(config_info.sources[key][-1]))
24
25        rows.append(CONFIG_FIELD_SEPARATOR.join(row))
26
27    rows.sort()
28
29    if (not args.skip_header):
30        header = ["Key", "Value"]
31        if (args.show_origin):
32            header.append("Origin")
33
34        rows.insert(0, (CONFIG_FIELD_SEPARATOR.join(header)))
35
36    print("\n".join(rows))
37    return 0
38
39def modify_parser(parser: argparse.ArgumentParser) -> None:
40    """ Add this CLI's flags to the given parser. """
41
42    group = parser.add_argument_group('list options')
43
44    group.add_argument("--include-cli", dest = 'include_cli',
45        action = 'store_true',
46        help = "Include implicit CLI config values (values defined directly on the CLI but not with `--config`).",
47    )
48
49    group.add_argument("--show-origin", dest = 'show_origin',
50        action = 'store_true',
51        help = "Display where each configuration's value was obtained from.",
52    )
53
54    group.add_argument("--skip-header", dest = 'skip_header',
55        action = 'store_true',
56        help = 'Skip headers when displaying configs.',
57    )
CONFIG_FIELD_SEPARATOR: str = '\t'
def run(args: argparse.Namespace) -> int:
12def run(args: argparse.Namespace) -> int:
13    """ Run the target command and return the suggested exit status. """
14
15    config_info = args._config_info
16
17    rows = []
18    for (key, value) in config_info.raw_config.items():
19        if ((not args.include_cli) and isinstance(args._config_info.sources[key][0].spec, edq.config.source.CLIImplicitSpec)):
20            continue
21
22        row = [key, str(value)]
23        if (args.show_origin):
24            row.append(str(config_info.sources[key][-1]))
25
26        rows.append(CONFIG_FIELD_SEPARATOR.join(row))
27
28    rows.sort()
29
30    if (not args.skip_header):
31        header = ["Key", "Value"]
32        if (args.show_origin):
33            header.append("Origin")
34
35        rows.insert(0, (CONFIG_FIELD_SEPARATOR.join(header)))
36
37    print("\n".join(rows))
38    return 0

Run the target command and return the suggested exit status.

def modify_parser(parser: argparse.ArgumentParser) -> None:
40def modify_parser(parser: argparse.ArgumentParser) -> None:
41    """ Add this CLI's flags to the given parser. """
42
43    group = parser.add_argument_group('list options')
44
45    group.add_argument("--include-cli", dest = 'include_cli',
46        action = 'store_true',
47        help = "Include implicit CLI config values (values defined directly on the CLI but not with `--config`).",
48    )
49
50    group.add_argument("--show-origin", dest = 'show_origin',
51        action = 'store_true',
52        help = "Display where each configuration's value was obtained from.",
53    )
54
55    group.add_argument("--skip-header", dest = 'skip_header',
56        action = 'store_true',
57        help = 'Skip headers when displaying configs.',
58    )

Add this CLI's flags to the given parser.