Skip to content

Commit f16afb0

Browse files
authored
feature(cli) - Support package as an alias for the submit --dry-run argument in the cfn-cli (#913)
* Initial attempt at package argument * Updated help discription for package * Added tests for package argument * Clarify that it is minimum and maximum length in subproperty and hooks docs * Revert "Clarify that it is minimum and maximum length in subproperty and hooks docs" This reverts commit 6fd5662. * Update README to include package command * remove unnecessary argument for test * Add empty profile name argument for package command * update test for profile_name parameter
1 parent 5848cc8 commit f16afb0

File tree

4 files changed

+61
-0
lines changed

4 files changed

+61
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ cfn submit --dry-run #prepares schema handler package without submitting for reg
4646
cfn submit --set-default # if successfully registered, set submitted version to be the new default version
4747
```
4848

49+
### Command: package
50+
51+
This is to create a schema handler package without submitting equivalent to `cfn submit --dry-run`
52+
53+
```bash
54+
cfn package
55+
```
56+
4957
### Command: test
5058

5159
To run the contract tests for a resource type, use the `test` command.

src/rpdk/core/cli.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from .generate import setup_subparser as generate_setup_subparser
1717
from .init import setup_subparser as init_setup_subparser
1818
from .invoke import setup_subparser as invoke_setup_subparser
19+
from .package import setup_subparser as package_setup_subparser
1920
from .submit import setup_subparser as submit_setup_subparser
2021
from .test import setup_subparser as test_setup_subparser
2122
from .validate import setup_subparser as validate_setup_subparser
@@ -89,7 +90,9 @@ def no_command(args):
8990
invoke_setup_subparser(subparsers, parents)
9091
unittest_patch_setup_subparser(subparsers, parents)
9192
build_image_setup_subparser(subparsers, parents)
93+
package_setup_subparser(subparsers, parents)
9294
extensions_setup_subparser(subparsers, parents)
95+
9396
args = parser.parse_args(args=args_in)
9497

9598
setup_logging(args.verbose)

src/rpdk/core/package.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""This is the same as cfn submit --dryrun, it will create a local package without uploading.
2+
3+
Projects can be created via the 'init' sub command.
4+
"""
5+
import logging
6+
7+
from .project import Project
8+
9+
LOG = logging.getLogger(__name__)
10+
11+
12+
def package(_args):
13+
project = Project()
14+
project.load()
15+
project.submit(
16+
dry_run=True,
17+
endpoint_url=False,
18+
region_name=False,
19+
role_arn=False,
20+
use_role=False,
21+
set_default=False,
22+
profile_name=False,
23+
)
24+
25+
26+
def setup_subparser(subparsers, parents):
27+
parser = subparsers.add_parser("package", description=__doc__, parents=parents)
28+
parser.set_defaults(command=package)

tests/test_package.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from unittest.mock import Mock, patch
2+
3+
from rpdk.core.cli import main
4+
from rpdk.core.project import Project
5+
6+
7+
def test_package_command_valid_schema():
8+
mock_project = Mock(spec=Project)
9+
10+
with patch("rpdk.core.package.Project", autospec=True, return_value=mock_project):
11+
main(args_in=["package"])
12+
13+
mock_project.load.assert_called_once()
14+
mock_project.submit.assert_called_once_with(
15+
dry_run=True,
16+
endpoint_url=False,
17+
region_name=False,
18+
role_arn=False,
19+
use_role=False,
20+
set_default=False,
21+
profile_name=False,
22+
)

0 commit comments

Comments
 (0)