-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.py
More file actions
106 lines (88 loc) · 2.91 KB
/
cli.py
File metadata and controls
106 lines (88 loc) · 2.91 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This is the entry point for the command-line interface (CLI) application.
It can be used as a handy facility for running the task from a command line.
.. note::
To learn more about Click visit the
`project website <http://click.pocoo.org/5/>`_. There is also a very
helpful `tutorial video <https://www.youtube.com/watch?v=kNke39OZ2k0>`_.
To learn more about running Luigi, visit the Luigi project's
`Read-The-Docs <http://luigi.readthedocs.io/en/stable/>`_ page.
.. currentmodule:: lambda_layer.cli
.. moduleauthor:: Pat Daburu <[email protected]>
"""
import logging
import click
from .__init__ import __version__
from . import env
from .package import make
from .config import Config
LOGGING_LEVELS = {
0: logging.NOTSET,
1: logging.ERROR,
2: logging.WARN,
3: logging.INFO,
4: logging.DEBUG,
} #: a mapping of `verbose` option counts to logging levels
class Info(object):
"""An information object to pass data between CLI functions."""
def __init__(self): # Note: This object must have an empty constructor.
"""Create a new instance."""
self.verbose: int = 0
# pass_info is a decorator for functions that pass 'Info' objects.
#: pylint: disable=invalid-name
pass_info = click.make_pass_decorator(Info, ensure=True)
# Change the options to below to suit the actual options for your task (or
# tasks).
@click.group()
@click.option("--verbose", "-v", count=True, help="Enable verbose output.")
@pass_info
def cli(info: Info, verbose: int):
"""Run lambda-layer."""
# Use the verbosity count to determine the logging level...
if verbose > 0:
logging.basicConfig(
level=LOGGING_LEVELS[verbose]
if verbose in LOGGING_LEVELS
else logging.DEBUG
)
click.echo(
click.style(
f"Verbose logging is enabled. "
f"(LEVEL={logging.getLogger().getEffectiveLevel()})",
fg="yellow",
)
)
info.verbose = verbose
@cli.command()
@click.option(
'config', '-c', '--config',
envvar=env.Vars.LAMBDA_LAYER_CONFIG.name,
default=None,
type=click.Path(exists=True))
@pass_info
def package(
_: Info,
config: str
):
"""Create configured packages."""
# Figure out where the configuration file is.
_configf = (
config if config
else env.get(env.Vars.LAMBDA_LAYER_CONFIG)
)
# Load the configuration.
config = Config.loadf(_configf)
# Iterate the layers in the configuration and create each one.
for layer in config.layers:
click.echo(f"name: {layer.name}")
click.echo(f"version: {layer.version}")
make(
dist_dir=env.get(env.Vars.LAMBDA_LAYER_DIST_DIR),
layer=layer
)
@cli.command()
def version():
"""Get the library version."""
click.echo(click.style(f"{__version__}", bold=True))