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): CliArguments interface generated from config.ts #32556

Merged
merged 18 commits into from
Dec 19, 2024

Conversation

kaizencc
Copy link
Contributor

@kaizencc kaizencc commented Dec 17, 2024

This PR:

  • generates a new type, CliArguments which is an interface created from the cli source-of-truth in config.ts.
  • renames yargs-gen into cli-args-gen to better reflect what we are generating now

The purpose of CliArguments is to eventually replace our current Arguments type, turning it into a strongly-typed object. Arguments today looks like this:

export type Arguments = {
  readonly _: [Command, ...string[]];
  readonly exclusively?: boolean;
  readonly STACKS?: string[];
  readonly lookups?: boolean;
  readonly [name: string]: unknown;
};

And because the last line in the definition essentially accepts any kind of property, we end up passing in and using values that are not documented anywhere. The purpose of this PR is to introduce a better type to enforce that the args object in cli.ts only holds values we expect. We are not currently using the new type anywhere; that will be done in a subsequent PR.

The success criteria of this PR is that we are generating a new type from the source of truth that will eventually represent the type of the object we receive from CLI inputs.

Part of #32474

Checklist


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

Sorry, something went wrong.

@kaizencc kaizencc requested a review from a team as a code owner December 17, 2024 19:01
@kaizencc kaizencc changed the title chore(cli): add CliArguments type generated from config.ts chore(cli): CliArguments type generated from config.ts Dec 17, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team December 17, 2024 19:01
@github-actions github-actions bot added the p2 label Dec 17, 2024
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 17, 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 17, 2024
/**
* The CLI command name followed by any properties of the command
*/
readonly _: Array<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.

This is supposed to be typed [Command, ...string] but I don't have a good way of doing that via code-gen (enlighten me if you think differently). Instead I plan to validate that the first array element is a valid Command when I am converting the input into this type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we might also want to pull out the additional elements into its own STACKS property, as that is what the current Arguments type does:

export type Arguments = {
  readonly _: [Command, ...string[]];
  readonly exclusively?: boolean;
  readonly STACKS?: string[];
  readonly lookups?: boolean;
  readonly [name: string]: unknown;
};

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. You could just not include it hear, keep this interface to just the auto-generated stuff and inside the CLI have an interface extending the codegen'd one with whatever extra types you need.

  2. Misusing ambient should work: Type.ambient('[Command, ...string[]]') You'll have to import Command manually though.

Copy link
Contributor

Choose a reason for hiding this comment

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

Otherwise we would need proper support for this in typewriter:

  • A new Type.variadic(elementType: Type)
  • A new Type.tuple(...elementTypes: Type[])

Copy link

codecov bot commented Dec 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.13%. Comparing base (d5e45c4) to head (5f2d7c7).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #32556      +/-   ##
==========================================
+ Coverage   78.86%   79.13%   +0.26%     
==========================================
  Files         108      107       -1     
  Lines        7165     7131      -34     
  Branches     1319     1319              
==========================================
- Hits         5651     5643       -8     
+ Misses       1330     1304      -26     
  Partials      184      184              
Flag Coverage Δ
suite.unit 79.13% <ø> (+0.26%) ⬆️

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

Components Coverage Δ
packages/aws-cdk 79.13% <ø> (+0.26%) ⬆️

@kaizencc kaizencc changed the title chore(cli): CliArguments type generated from config.ts chore(cli): CliArguments interface generated from config.ts Dec 17, 2024
@aws-cdk-automation
Copy link
Collaborator

➡️ PR build request submitted to test-main-pipeline ⬅️

A maintainer must now check the pipeline and add the pr-linter/cli-integ-tested label once the pipeline succeeds.

@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 17, 2024
@aws-cdk-automation aws-cdk-automation dismissed their stale review December 17, 2024 23:02

✅ 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 17, 2024
Copy link
Contributor

@mrgrain mrgrain left a comment

Choose a reason for hiding this comment

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

Note: The package rename could have been a separate PR that would be very easy to approve.

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

mergify bot commented Dec 19, 2024

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).

Copy link
Contributor

mergify bot commented Dec 19, 2024

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).

Copy link
Contributor

mergify bot commented Dec 19, 2024

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #32556 has been dequeued. The pull request could not be merged. This could be related to an activated branch protection or ruleset rule that prevents us from merging. (detail: 3 of 6 required status checks have not succeeded: 2 expected and 1 failing.).

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

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

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

Copy link
Contributor

mergify bot commented Dec 19, 2024

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).

Copy link
Contributor

mergify bot commented Dec 19, 2024

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #32556 has been dequeued. The pull request could not be merged. This could be related to an activated branch protection or ruleset rule that prevents us from merging. (detail: 4 of 6 required status checks are expected.).

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

@kaizencc
Copy link
Contributor Author

@Mergifyio refresh

Copy link
Contributor

mergify bot commented Dec 19, 2024

refresh

✅ Pull request refreshed

@mergify mergify bot merged commit dc1647e into main Dec 19, 2024
16 of 17 checks passed
@mergify mergify bot deleted the conroy/codegenwork branch December 19, 2024 21:09
Copy link

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 Dec 19, 2024
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.

None yet

3 participants