Skip to content
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
1 change: 1 addition & 0 deletions installer/pyinstaller/hook-samcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"samcli.commands.deploy",
"samcli.commands.logs",
"samcli.commands.publish",
"samcli.commands.delete",
"samcli.commands.pipeline.pipeline",
"samcli.commands.pipeline.init",
"samcli.commands.pipeline.bootstrap",
Expand Down
13 changes: 9 additions & 4 deletions samcli/cli/cli_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ class TomlProvider:
A parser for toml configuration files
"""

def __init__(self, section=None):
def __init__(self, section=None, cmd_names=None):
"""
The constructor for TomlProvider class
:param section: section defined in the configuration file nested within `cmd`
:param cmd_names: cmd_name defined in the configuration file
"""
self.section = section
self.cmd_names = cmd_names

def __call__(self, config_path, config_env, cmd_names):
"""
Expand Down Expand Up @@ -67,18 +69,21 @@ def __call__(self, config_path, config_env, cmd_names):
LOG.debug("Config file '%s' does not exist", samconfig.path())
return resolved_config

if not self.cmd_names:
self.cmd_names = cmd_names

try:
LOG.debug(
"Loading configuration values from [%s.%s.%s] (env.command_name.section) in config file at '%s'...",
config_env,
cmd_names,
self.cmd_names,
self.section,
samconfig.path(),
)

# NOTE(TheSriram): change from tomlkit table type to normal dictionary,
# so that click defaults work out of the box.
resolved_config = dict(samconfig.get_all(cmd_names, self.section, env=config_env).items())
resolved_config = dict(samconfig.get_all(self.cmd_names, self.section, env=config_env).items())
LOG.debug("Configuration values successfully loaded.")
LOG.debug("Configuration values are: %s", resolved_config)

Expand All @@ -87,7 +92,7 @@ def __call__(self, config_path, config_env, cmd_names):
"Error reading configuration from [%s.%s.%s] (env.command_name.section) "
"in configuration file at '%s' with : %s",
config_env,
cmd_names,
self.cmd_names,
self.section,
samconfig.path(),
str(ex),
Expand Down
1 change: 1 addition & 0 deletions samcli/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"samcli.commands.local.local",
"samcli.commands.package",
"samcli.commands.deploy",
"samcli.commands.delete",
"samcli.commands.logs",
"samcli.commands.publish",
"samcli.commands.pipeline.pipeline",
Expand Down
2 changes: 2 additions & 0 deletions samcli/commands/_utils/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
AWS_GLUE_JOB = "AWS::Glue::Job"
AWS_SERVERLESS_STATEMACHINE = "AWS::Serverless::StateMachine"
AWS_STEPFUNCTIONS_STATEMACHINE = "AWS::StepFunctions::StateMachine"
AWS_ECR_REPOSITORY = "AWS::ECR::Repository"

METADATA_WITH_LOCAL_PATHS = {AWS_SERVERLESSREPO_APPLICATION: ["LicenseUrl", "ReadmeUrl"]}

Expand Down Expand Up @@ -50,6 +51,7 @@
RESOURCES_WITH_IMAGE_COMPONENT = {
AWS_SERVERLESS_FUNCTION: ["ImageUri"],
AWS_LAMBDA_FUNCTION: ["Code"],
AWS_ECR_REPOSITORY: ["RepositoryName"],
}


Expand Down
6 changes: 6 additions & 0 deletions samcli/commands/delete/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"""
`sam delete` command
"""

# Expose the cli object here
from .command import cli # noqa
101 changes: 101 additions & 0 deletions samcli/commands/delete/command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
"""
CLI command for "delete" command
"""

import logging

import click
from samcli.cli.main import aws_creds_options, common_options, pass_context, print_cmdline_args

from samcli.lib.utils.version_checker import check_newer_version

SHORT_HELP = "Delete an AWS SAM application and the artifacts created by sam deploy."

HELP_TEXT = """The sam delete command deletes the CloudFormation
stack and all the artifacts which were created using sam deploy.

\b
e.g. sam delete

\b
"""

LOG = logging.getLogger(__name__)


@click.command(
"delete",
short_help=SHORT_HELP,
context_settings={"ignore_unknown_options": False, "allow_interspersed_args": True, "allow_extra_args": True},
help=HELP_TEXT,
)
@click.option(
"--stack-name",
required=False,
help="The name of the AWS CloudFormation stack you want to delete. ",
)
@click.option(
"--config-file",
help=(
"The path and file name of the configuration file containing default parameter values to use. "
"Its default value is 'samconfig.toml' in project directory. For more information about configuration files, "
"see: "
"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html."
),
type=click.STRING,
default="samconfig.toml",
show_default=True,
)
@click.option(
"--config-env",
help=(
"The environment name specifying the default parameter values in the configuration file to use. "
"Its default value is 'default'. For more information about configuration files, see: "
"https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html."
),
type=click.STRING,
default="default",
show_default=True,
)
@click.option(
"--no-prompts",
help=("Specify this flag to allow SAM CLI to skip through the guided prompts."),
is_flag=True,
required=False,
)
@aws_creds_options
@common_options
@pass_context
@check_newer_version
@print_cmdline_args
def cli(ctx, stack_name: str, config_file: str, config_env: str, no_prompts: bool):
"""
`sam delete` command entry point
"""

# All logic must be implemented in the ``do_cli`` method. This helps with easy unit testing
do_cli(
stack_name=stack_name,
region=ctx.region,
config_file=config_file,
config_env=config_env,
profile=ctx.profile,
no_prompts=no_prompts,
) # pragma: no cover


def do_cli(stack_name: str, region: str, config_file: str, config_env: str, profile: str, no_prompts: bool):
"""
Implementation of the ``cli`` method
"""
from samcli.commands.delete.delete_context import DeleteContext

with DeleteContext(
stack_name=stack_name,
region=region,
profile=profile,
config_file=config_file,
config_env=config_env,
no_prompts=no_prompts,
) as delete_context:
delete_context.run()
Loading