forked from aws/aws-sam-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.py
More file actions
78 lines (59 loc) · 2.02 KB
/
options.py
File metadata and controls
78 lines (59 loc) · 2.02 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
"""
This file contains common CLI options common to all commands. As we add more commands, this will
become a repository of options that other commands could use when needed.
"""
import click
from samcli.cli.context import Context
def debug_option(f):
"""
Configures --debug option for CLI
:param f: Callback Function to be passed to Click
"""
def callback(ctx, param, value):
state = ctx.ensure_object(Context)
state.debug = value
return value
return click.option(
"--debug",
expose_value=False,
is_eager=True,
is_flag=True,
envvar="SAM_DEBUG",
help="Turn on debug logging to print debug message generated by AWS SAM CLI and display timestamps.",
callback=callback,
)(f)
def region_option(f):
"""
Configures --region option for CLI
:param f: Callback Function to be passed to Click
"""
def callback(ctx, param, value):
state = ctx.ensure_object(Context)
from botocore import exceptions, utils
from samcli.commands.exceptions import RegionError
try:
utils.validate_region_name(value)
except exceptions.InvalidRegionError as ex:
raise RegionError(
message=f"Provided region: {value} doesn't match a supported format", wrapped_from=ex.__class__.__name__
) from ex
state.region = value
return value
return click.option(
"--region", expose_value=False, help="Set the AWS Region of the service. (e.g. us-east-1)", callback=callback
)(f)
def profile_option(f):
"""
Configures --profile option for CLI
:param f: Callback Function to be passed to Click
"""
def callback(ctx, param, value):
state = ctx.ensure_object(Context)
state.profile = value
return value
return click.option(
"--profile",
expose_value=False,
help="Select a specific profile from your credential file to get AWS credentials.",
callback=callback,
)(f)