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

feature(cli) - Support package as an alias for the submit --dry-run argument in the cfn-cli #913

Merged
merged 13 commits into from
Oct 6, 2023
Merged
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ cfn submit --dry-run #prepares schema handler package without submitting for reg
cfn submit --set-default # if successfully registered, set submitted version to be the new default version
```

### Command: package

This is to create a schema handler package without submitting equivalent to `cfn submit --dry-run`

```bash
cfn package
```

### Command: test

To run the contract tests for a resource type, use the `test` command.
Expand Down
3 changes: 3 additions & 0 deletions src/rpdk/core/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .generate import setup_subparser as generate_setup_subparser
from .init import setup_subparser as init_setup_subparser
from .invoke import setup_subparser as invoke_setup_subparser
from .package import setup_subparser as package_setup_subparser
from .submit import setup_subparser as submit_setup_subparser
from .test import setup_subparser as test_setup_subparser
from .validate import setup_subparser as validate_setup_subparser
Expand Down Expand Up @@ -89,7 +90,9 @@ def no_command(args):
invoke_setup_subparser(subparsers, parents)
unittest_patch_setup_subparser(subparsers, parents)
build_image_setup_subparser(subparsers, parents)
package_setup_subparser(subparsers, parents)
extensions_setup_subparser(subparsers, parents)

args = parser.parse_args(args=args_in)

setup_logging(args.verbose)
Expand Down
28 changes: 28 additions & 0 deletions src/rpdk/core/package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""This is the same as cfn submit --dryrun, it will create a local package without uploading.

Projects can be created via the 'init' sub command.
mmaeng marked this conversation as resolved.
Show resolved Hide resolved
"""
import logging

from .project import Project

LOG = logging.getLogger(__name__)


def package(_args):
project = Project()
project.load()
project.submit(
dry_run=True,
endpoint_url=False,
region_name=False,
role_arn=False,
use_role=False,
set_default=False,
profile_name=False,
)


def setup_subparser(subparsers, parents):
parser = subparsers.add_parser("package", description=__doc__, parents=parents)
parser.set_defaults(command=package)
22 changes: 22 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from unittest.mock import Mock, patch

from rpdk.core.cli import main
from rpdk.core.project import Project


def test_package_command_valid_schema():
mock_project = Mock(spec=Project)

with patch("rpdk.core.package.Project", autospec=True, return_value=mock_project):
main(args_in=["package"])

mock_project.load.assert_called_once()
mock_project.submit.assert_called_once_with(
dry_run=True,
endpoint_url=False,
region_name=False,
role_arn=False,
use_role=False,
set_default=False,
profile_name=False,
)