Skip to content

Commit d073c83

Browse files
authored
Add --output argument for formatting output (#78)
1 parent 3deefb4 commit d073c83

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ newrelic-lambda functions list --filter installed
159159
| Option | Required? | Description |
160160
|--------|-----------|-------------|
161161
| `--filter` or `-f` | No | Filter to be applied to list of functions. Options are `all`, `installed` and `not-installed`. Defaults to `all`. |
162+
| `--output` or `-o` | No | Specify the desired output format. Supports `table` and `text`. Defaults to `table`. |
162163
| `--aws-profile` or `-p` | No | The AWS profile to use for this command. Can also use `AWS_PROFILE`. Will also check `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables if not using AWS CLI. |
163164
| `--aws-region` or `-r` | No | The AWS region to use for this command. Can use `AWS_DEFAULT_REGION` environment variable. Defaults to AWS session region. |
164165

newrelic_lambda_cli/cli/functions.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,15 @@ def register(group):
2828
help="Apply a filter to the list.",
2929
type=click.Choice(["all", "installed", "not-installed"]),
3030
)
31-
def list(aws_profile, aws_region, aws_permissions_check, filter):
31+
@click.option(
32+
"--output",
33+
"-o",
34+
default="table",
35+
help="Formet output",
36+
show_default=True,
37+
type=click.Choice(["table", "text"]),
38+
)
39+
def list(aws_profile, aws_region, aws_permissions_check, filter, output):
3240
"""List AWS Lambda Functions"""
3341
_, rows = shutil.get_terminal_size((80, 50))
3442
session = boto3.Session(profile_name=aws_profile, region_name=aws_region)
@@ -38,7 +46,7 @@ def list(aws_profile, aws_region, aws_permissions_check, filter):
3846

3947
funcs = functions.list_functions(session, filter)
4048

41-
def _format(funcs, header=False):
49+
def format_table(funcs, header=False):
4250
table = []
4351
for func in funcs:
4452
table.append(
@@ -52,6 +60,27 @@ def _format(funcs, header=False):
5260
table, headers=["Function Name", "Runtime", "Installed"] if header else []
5361
).rstrip()
5462

63+
def format_text(funcs, header=False):
64+
text = []
65+
if header:
66+
text.append("\t".join(["Function Name", "Runtime", "Installed"]))
67+
for func in funcs:
68+
text.append(
69+
"\t".join(
70+
[
71+
func.get("FunctionName"),
72+
func.get("Runtime"),
73+
"Yes" if func.get("x-new-relic-enabled", False) else "No",
74+
]
75+
)
76+
)
77+
return "\n".join(text)
78+
79+
_format = format_table
80+
81+
if output == "text":
82+
_format = format_text
83+
5584
buffer = []
5685
for i, func in enumerate(funcs):
5786
buffer.append(func)

0 commit comments

Comments
 (0)