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(cli): function to turn yargs output to cliArguments #32696

Merged
merged 14 commits into from
Jan 2, 2025

Conversation

kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Dec 31, 2024

This PR has no impact on CLI functionality

This PR generates a new function, convertToCliArgs, that takes in the output of the yargs configuration and turns it into a CliArguments type. This allows us to subsequently utilize the strongly-typed object in cli.ts, but this PR does not actually do that.

The ultimate benefit is that now we can ensure exactly what goes into this type. We can then enforce that any property allowed to be specified via cdk.json is also an option in the cli. When all my refactoring is done, there will be no options that are only specified via cdk.json, and no options only specified via CLI.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@aws-cdk-automation aws-cdk-automation requested a review from a team December 31, 2024 15:16
@github-actions github-actions bot added the p2 label Dec 31, 2024
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 31, 2024
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

A comment requesting an exemption should contain the text Exemption Request. Additionally, if clarification is needed add Clarification Request to a comment.

@aws-cdk-automation aws-cdk-automation added the pr/needs-cli-test-run This PR needs CLI tests run against it. label Dec 31, 2024
Copy link

codecov bot commented Dec 31, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.96%. Comparing base (3b162fc) to head (7c310b2).

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32696   +/-   ##
=======================================
  Coverage   66.96%   66.96%           
=======================================
  Files         329      329           
  Lines       18663    18663           
  Branches     3258     3258           
=======================================
  Hits        12497    12497           
  Misses       5839     5839           
  Partials      327      327           
Flag Coverage Δ
suite.unit 66.96% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 80.71% <ø> (ø)
packages/aws-cdk-lib/core 82.08% <ø> (ø)

@kaizencc kaizencc marked this pull request as ready for review December 31, 2024 17:34
@kaizencc kaizencc requested a review from a team as a code owner December 31, 2024 17:34
});
}

function buildCliArgsFunction(config: CliConfig): string {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for all of the following buildXxx functions, I am sure there is a more idiomatic way of achieving what I want via typewriter. I have done it this way because it felt the simplest for me as of right now, and I believe it will be easier to refactor later with the benefit of knowing exactly what the generated function should look like.

@kaizencc kaizencc added pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested and removed pr/needs-cli-test-run This PR needs CLI tests run against it. labels Dec 31, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 31, 2024 17:42

✅ Updated pull request passes all PRLinter validations. Dismissing previous PRLinter review.

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Dec 31, 2024
packages/aws-cdk/test/cli-arguments.test.ts Outdated Show resolved Hide resolved
codecov.yml Outdated Show resolved Hide resolved
break;

case 'acknowledge':
commandOptions = {};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at our current for this command I see:

case 'ack':
return cli.acknowledge(args.ID);

Should this PR also handle positional arguments? I would expect we have a strongly typed args.acknowledge.id or something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. A big part of my refactor is to make sure we don't have to use args, argv, and configuration.settings everywhere and instead just have 1 object with arguments.

Currently those positional arguments are found in index 1 and beyond on argv._: argv._: [Command, ...string]

It will be a bit awkward to figure out the right way to deal with that, which I would like to do in a separate PR.

packages/aws-cdk/scripts/cli-args-gen.ts Show resolved Hide resolved
@@ -2,6 +2,7 @@
// GENERATED FROM packages/aws-cdk/lib/config.ts.
// Do not edit by hand; all changes will be overwritten at build time from the config file.
// -------------------------------------------------------------------------------------------
// istanbul ignore file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this actually do something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. I forgot to yarn build aws-cdk to remove them...

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 7c310b2
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 2, 2025
Copy link
Contributor

mergify bot commented Jan 2, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit efe7c2e into main Jan 2, 2025
22 of 23 checks passed
Copy link
Contributor

mergify bot commented Jan 2, 2025

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot deleted the conroy/commandenum branch January 2, 2025 18:16
Copy link

github-actions bot commented Jan 2, 2025

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution/core This is a PR that came from AWS. p2 pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants