carbonarc 1.0.0__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
carbonarc_cli/cli.py ADDED
@@ -0,0 +1,65 @@
1
+ import click
2
+ import logging
3
+
4
+ LOGGING_LEVELS = {
5
+ 0: logging.NOTSET,
6
+ 1: logging.DEBUG,
7
+ 2: logging.INFO,
8
+ 3: logging.WARN,
9
+ 4: logging.ERROR,
10
+ } #: a mapping of `verbose` option counts to logging levels
11
+
12
+
13
+ class Config(object):
14
+ """An information object to pass data between CLI functions."""
15
+
16
+ def __init__(self):
17
+ """Create a new instance."""
18
+ pass
19
+
20
+
21
+ pass_config = click.make_pass_decorator(Config, ensure=True)
22
+
23
+
24
+ @click.group()
25
+ @click.option("--verbose", "-v", count=True, help="Enable verbose output.")
26
+ @click.pass_context
27
+ def cli(ctx, verbose: int):
28
+ """
29
+ Logging levels:
30
+ 0: NOTSET
31
+ 1: DEBUG
32
+ 2: INFO
33
+ 3: WARN
34
+ 4: ERROR
35
+ """
36
+ ctx.obj = Config()
37
+
38
+ # Use the verbosity count to determine the logging level...
39
+ if verbose > 0:
40
+ logging.basicConfig(
41
+ level=LOGGING_LEVELS[verbose]
42
+ if verbose in LOGGING_LEVELS
43
+ else logging.DEBUG
44
+ )
45
+ click.echo(
46
+ click.style(
47
+ f"Verbose logging is enabled. "
48
+ f"(LEVEL={logging.getLogger().getEffectiveLevel()})",
49
+ fg="yellow",
50
+ )
51
+ )
52
+
53
+
54
+ ################
55
+ # Carbon Arc CLI
56
+ ################
57
+ @cli.group()
58
+ @click.pass_obj
59
+ def package(ctx):
60
+ """Package commands"""
61
+ pass
62
+
63
+
64
+ if __name__ == "__main__":
65
+ cli()