-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Merge develop into feat/terraform-start-api (#5388)
* chore: update aws-sam-translator to 1.69.0 (#5370) Co-authored-by: GitHub Action <action@github.com> * feat: sam remote invoke help text and UX fixes (#5366) * Improve remote invoke help text and fix some UX bugs * Updated help text for parameter option * Updated test class name * Updated test method name * Updated help text for output-format and event-file * Address feedback * Updated help text for parameter option * Changed --output-format name to output and the values to text/json * Handle empty event for lambda and read from stdin when - is passed for event-file * chore: temporary pin python version to 3.7.16 (#5384) * chore: temporary pin python version to 3.7.16 * fix github action syntax error * Updated cfn-lint to support ruby3.2 in validate (#5375) * Remove unneeded test cases (#5374) * Remove unneeded test cases * Removing the two integ test cases as there is already coverage in unit test for cases that no region is specified --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: GitHub Action <action@github.com> Co-authored-by: hnnasit <84355507+hnnasit@users.noreply.github.com> Co-authored-by: Mohamed Elasmar <71043312+moelasmar@users.noreply.github.com> Co-authored-by: Lucas <12496191+lucashuy@users.noreply.github.com> Co-authored-by: Wing Fung Lau <4760060+hawflau@users.noreply.github.com>
- Loading branch information
1 parent
4b9f1df
commit 93979d9
Showing
25 changed files
with
471 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
""" | ||
Invoke Command Class. | ||
""" | ||
import json | ||
|
||
from click import Context, style | ||
|
||
from samcli.cli.core.command import CoreCommand | ||
from samcli.cli.row_modifiers import RowDefinition, ShowcaseRowModifier | ||
from samcli.commands.remote.invoke.core.formatters import RemoteInvokeCommandHelpTextFormatter | ||
from samcli.commands.remote.invoke.core.options import OPTIONS_INFO | ||
|
||
|
||
class RemoteInvokeCommand(CoreCommand): | ||
class CustomFormatterContext(Context): | ||
formatter_class = RemoteInvokeCommandHelpTextFormatter | ||
|
||
context_class = CustomFormatterContext | ||
|
||
@staticmethod | ||
def format_examples(ctx: Context, formatter: RemoteInvokeCommandHelpTextFormatter): | ||
with formatter.indented_section(name="Examples", extra_indents=1): | ||
with formatter.indented_section(name="Invoke default lambda function with empty event", extra_indents=1): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
text="\n", | ||
), | ||
RowDefinition( | ||
name=style(f"${ctx.command_path} --stack-name hello-world"), | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
with formatter.indented_section( | ||
name="Invoke default lambda function with event passed as text input", extra_indents=1 | ||
): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
text="\n", | ||
), | ||
RowDefinition( | ||
name=style( | ||
f"${ctx.command_path} --stack-name hello-world -e '{json.dumps({'message':'hello!'})}'" | ||
), | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
with formatter.indented_section(name="Invoke named lambda function with an event file", extra_indents=1): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
text="\n", | ||
), | ||
RowDefinition( | ||
name=style( | ||
f"${ctx.command_path} --stack-name " | ||
f"hello-world HelloWorldFunction --event-file event.json" | ||
), | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
with formatter.indented_section(name="Invoke lambda function with event as stdin input", extra_indents=1): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
text="\n", | ||
), | ||
RowDefinition( | ||
name=style( | ||
f"$ echo '{json.dumps({'message':'hello!'})}' | " | ||
f"{ctx.command_path} HelloWorldFunction --event-file -" | ||
), | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
with formatter.indented_section( | ||
name="Invoke lambda function using lambda ARN and get the full AWS API response", extra_indents=1 | ||
): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
text="\n", | ||
), | ||
RowDefinition( | ||
name=style( | ||
f"${ctx.command_path} arn:aws:lambda:us-west-2:123456789012:function:my-function -e <>" | ||
f" --output json" | ||
), | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
with formatter.indented_section( | ||
name="Asynchronously invoke lambda function with additional boto parameters", extra_indents=1 | ||
): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
text="\n", | ||
), | ||
RowDefinition( | ||
name=style( | ||
f"${ctx.command_path} HelloWorldFunction -e <> " | ||
f"--parameter InvocationType=Event --parameter Qualifier=MyQualifier" | ||
), | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
with formatter.indented_section( | ||
name="Dry invoke a lambda function to validate parameter values and user/role permissions", | ||
extra_indents=1, | ||
): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
text="\n", | ||
), | ||
RowDefinition( | ||
name=style( | ||
f"${ctx.command_path} HelloWorldFunction -e <> --output json " | ||
f"--parameter InvocationType=DryRun" | ||
), | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
|
||
@staticmethod | ||
def format_acronyms(formatter: RemoteInvokeCommandHelpTextFormatter): | ||
with formatter.indented_section(name="Acronyms", extra_indents=1): | ||
formatter.write_rd( | ||
[ | ||
RowDefinition( | ||
name="ARN", | ||
text="Amazon Resource Name", | ||
extra_row_modifiers=[ShowcaseRowModifier()], | ||
), | ||
] | ||
) | ||
|
||
def format_options(self, ctx: Context, formatter: RemoteInvokeCommandHelpTextFormatter) -> None: # type:ignore | ||
# NOTE: `ignore` is put in place here for mypy even though it is the correct behavior, | ||
# as the `formatter_class` can be set in subclass of Command. If ignore is not set, | ||
# mypy raises argument needs to be HelpFormatter as super class defines it. | ||
|
||
self.format_description(formatter) | ||
RemoteInvokeCommand.format_examples(ctx, formatter) | ||
RemoteInvokeCommand.format_acronyms(formatter) | ||
|
||
CoreCommand._format_options( | ||
ctx=ctx, params=self.get_params(ctx), formatter=formatter, formatting_options=OPTIONS_INFO | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
Remote Invoke Command Formatter. | ||
""" | ||
from samcli.cli.formatters import RootCommandHelpTextFormatter | ||
from samcli.cli.row_modifiers import BaseLineRowModifier | ||
from samcli.commands.remote.invoke.core.options import ALL_OPTIONS | ||
|
||
|
||
class RemoteInvokeCommandHelpTextFormatter(RootCommandHelpTextFormatter): | ||
ADDITIVE_JUSTIFICATION = 17 | ||
|
||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
# NOTE: Add Additional space after determining the longest option. | ||
# However, do not justify with padding for more than half the width of | ||
# the terminal to retain aesthetics. | ||
self.left_justification_length = min( | ||
max([len(option) for option in ALL_OPTIONS]) + self.ADDITIVE_JUSTIFICATION, | ||
self.width // 2 - self.indent_increment, | ||
) | ||
self.modifiers = [BaseLineRowModifier()] |
Oops, something went wrong.