Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add required options for package and deploy #961

Merged
merged 3 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions samcli/commands/deploy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,40 @@
SHORT_HELP = "Deploy an AWS SAM application. This is an alias for 'aws cloudformation deploy'."


@click.command("deploy", short_help=SHORT_HELP, context_settings={"ignore_unknown_options": True})
HELP_TEXT = """The sam deploy command creates a Cloudformation Stack and deploys your resources.

\b
e.g. sam deploy sam deploy --template-file packaged.yaml --stack-name sam-app --capabilities CAPABILITY_IAM

\b
This is an alias for aws cloudformation deploy. To learn about other parameters you can use,
run aws cloudformation deploy help.
"""


@click.command("deploy", short_help=SHORT_HELP, context_settings={"ignore_unknown_options": True}, help=HELP_TEXT)
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
@click.option('--template-file',
required=True,
type=click.Path(),
help="The path where your AWS SAM template is located")
@click.option('--stack-name',
required=True,
help="The name of the AWS CloudFormation stack you're deploying to. "
"If you specify an existing stack, the command updates the stack. "
"If you specify a new stack, the command creates it.")
@common_options
@pass_context
def cli(ctx, args):
def cli(ctx, args, template_file, stack_name):

# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing
do_cli(args, template_file, stack_name) # pragma: no cover

do_cli(args) # pragma: no cover

def do_cli(args, template_file, stack_name):
args = args + ('--stack-name', stack_name)

def do_cli(args):
try:
execute_command("deploy", args, template_file=None)
execute_command("deploy", args, template_file=template_file)
except OSError as ex:
raise UserException(str(ex))
28 changes: 24 additions & 4 deletions samcli/commands/package/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,44 @@
SHORT_HELP = "Package an AWS SAM application. This is an alias for 'aws cloudformation package'."


@click.command("package", short_help=SHORT_HELP, context_settings={"ignore_unknown_options": True})
HELP_TEXT = """The SAM package command creates a zip of your code and dependencies and uploads it to S3. The command
returns a copy of your template, replacing references to local artifacts with the S3 location where the command
uploaded the artifacts.

\b
e.g. sam package --template-file template.yaml --output-template-file packaged.yaml
--s3-bucket REPLACE_THIS_WITH_YOUR_S3_BUCKET_NAME

\b
This is an alias for aws cloudformation package. To learn about other parameters you can use,
run aws cloudformation package help.
"""


@click.command("package", short_help=SHORT_HELP, context_settings={"ignore_unknown_options": True}, help=HELP_TEXT)
@click.option('--template-file',
default=_TEMPLATE_OPTION_DEFAULT_VALUE,
type=click.Path(),
callback=partial(get_or_default_template_file_name, include_build=True),
show_default=False,
help="The path where your AWS SAM template is located")
@click.option('--s3-bucket',
required=True,
help="The name of the S3 bucket where this command uploads the artifacts that "
"are referenced in your template.")
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
@common_options
@pass_context
def cli(ctx, args, template_file):
def cli(ctx, args, template_file, s3_bucket):

# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing

do_cli(args, template_file) # pragma: no cover
do_cli(args, template_file, s3_bucket) # pragma: no cover


def do_cli(args, template_file, s3_bucket):
args = args + ('--s3-bucket', s3_bucket)

def do_cli(args, template_file):
try:
execute_command("package", args, template_file)
except OSError as ex:
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/commands/test_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
class TestCli(TestCase):

def setUp(self):
self.args = ("--template-file", "file.yaml", "--stack-name", "stackName")
self.args = ('--force-upload',)
self.expected_args = self.args + ("--stack-name", "stackName")

@patch("samcli.commands.deploy.execute_command")
def test_deploy_must_pass_args(self, execute_command_mock):
execute_command_mock.return_value = True
deploy_cli(self.args)
execute_command_mock.assert_called_with("deploy", self.args, template_file=None)
deploy_cli(self.args, "file.yaml", 'stackName')
execute_command_mock.assert_called_with("deploy", self.expected_args, template_file='file.yaml')
7 changes: 4 additions & 3 deletions tests/unit/commands/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
class TestCli(TestCase):

def setUp(self):
self.args = ("--template-file", "file.yaml", "--s3-bucket", "bucketName")
self.args = (' --use - json',)
self.expected_args = self.args + ("--s3-bucket", "bucketName")

@patch("samcli.commands.package.execute_command")
def test_package_must_pass_args(self, execute_command_mock):
execute_command_mock.return_value = True
package_cli(self.args, "template_file")
execute_command_mock.assert_called_with("package", self.args, "template_file")
package_cli(self.args, "template_file", 'bucketName')
execute_command_mock.assert_called_with("package", self.expected_args, "template_file")