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

[cli] Improve type signature of CommandOption #11394

Merged
merged 5 commits into from
Apr 12, 2024

Conversation

erikareads
Copy link
Contributor

@erikareads erikareads commented Apr 5, 2024

The previous type signature of CommandOption did not cover all of the actual uses of option types throughout the codebase. This one may not cover all possible types, but comes much closer and allows us to literally state the type constructor used by arg to parse options.

This will allow for direct use of command.ts data structures so that Help output matches the actually parsed options used by every subcommand.

deploy/index.ts already shows an example of this, and a future pull request can build on that example by extracting that logic into a utility function.

Copy link

changeset-bot bot commented Apr 5, 2024

🦋 Changeset detected

Latest commit: 02c2604

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

@EndangeredMassa EndangeredMassa left a comment

Choose a reason for hiding this comment

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

Much nicer!

Comment on lines -96 to -102
if (
option.name === 'env' ||
option.name === 'build-env' ||
option.name === 'meta'
) {
argOptions[`--${option.name}`] = [String];
}
Copy link
Contributor

Choose a reason for hiding this comment

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

comment (non-blocking): In future PRs, I would add a PR comment to code like this making it clear why this condition could be removed.

It took me a few minutes to figure out why this change was here and useful.‏

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do that here by replying to your comment:

In this case, I can remove the extra condition since the CommandOption can now take constructors and [Constructor] directly as types, I don't need to rely on two sets of conditionals (the ternary above and this additional check) to get the parser type right.

Additionally, this was an interesting case, because these three commands specifically justified the multi: true in the CommandOption struct, but we can see here that we weren't using that information do the filtering and instead were hard-coding it.

The updated typing eliminates both issues.

@erikareads erikareads added the pr: automerge Automatically merge the PR when checks pass label Apr 11, 2024
@kodiakhq kodiakhq bot merged commit 21bbbb6 into main Apr 12, 2024
113 of 114 checks passed
@kodiakhq kodiakhq bot deleted the update_command_struct_types branch April 12, 2024 06:56
@onsclom onsclom mentioned this pull request Apr 12, 2024
onsclom added a commit that referenced this pull request Apr 12, 2024
The changes between #11348 and
#11394 were incompatible, causing
this type error.
This was referenced Apr 15, 2024
kodiakhq bot pushed a commit that referenced this pull request Apr 16, 2024
Extracting logic for turning a list of `CommandOption`s into a flagsSpecification for `parseArguments`. Builds on the work from #11396 and #11394.
kodiakhq bot pushed a commit that referenced this pull request Apr 17, 2024
Adds snapshot tests for the output from help as output by various commands. I expect to be changing some of the `Command` structs to continue the work started in [ [cli] Improve type signature of CommandOption #11394 ](#11394) especially as I build on work in [ Get flags specification #11433 ](#11433), and I want to be sure that the associated changes to help output are what we expect.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: automerge Automatically merge the PR when checks pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants