-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Update to System.CommandLine v2 #567
Conversation
@AArnott I can keep the argument types, arity, etc. the same, but how much do you care about the help header ( Before
After
Also, how much coverage over command line parsing do you roughly estimate you have? From the pipelines running against the PR, it's not readily apparent. |
Thanks. In general the formatting of the usage doc can change. And in particular I like the changes you're showing. What we must have a serious conversation about is if the actual command syntax changed in any way, because many pipelines just install the latest nbgv tool and run it, so a change in CLI syntax would break pipelines. I didn't see any changes here though. Are you aware of any? I don't think we have any automated tests for our nbgv CLI parsing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good. I see you marked this a WIP. What else needs to be done?
@@ -271,6 +283,7 @@ private static ExitCodes OnInstallCommand(string versionJsonRoot, string version | |||
// Validate given sources | |||
foreach (var source in sources) | |||
{ | |||
// TODO: Can declare Option<Uri> to validate argument during parsing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you recommend here? I lean toward keeping this code here because we can ensure an absolute Uri and (I am guessing) print a nicer error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do both, though maybe not that important. I agree checking if it's an absolute URI is good, but that can also be done at parsing time. Not only can any class with a constructor that takes a sole string be used, but you can have other validation to run at parsing time.
I marked it as a WIP because I didn't want to spend too much time cleaning it up just yet before we discussed it more. This is more POC. Apart from improving parse-time validation (you can also have it accept only legal file paths, or even validate that a file or directory exists at parsing time, not to mention the type-based parsing I mentioned), I also wanted to change the subcommand handlers so I can just call them directly instead of of another anonymous delegate to call them (though, if you don't mind, I could keep them - just adds an extra unnecessary layer).
As for command line handling, this should be compatible. If we're good with proceeding, I'll spend even more time effectively diffing --help
output for each subcommand and make sure they line up. I've kept parameter and argument names the same as well.
I know you have quite a bit of "mock repo" tests. It shouldn't be hard to add some tests that do the same thing and execute nbgv commands against it, should it? I could at least add some integration tests for mainline scenarios (maybe even a few corner case scenarios) and exec nbgv before and after my changes. Wouldn't hurt having those tests moving forward either to mitigate regressions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also wanted to change the subcommand handlers so I can just call them directly instead of of another anonymous delegate to call them (though, if you don't mind, I could keep them - just adds an extra unnecessary layer).
That sounds like a good change. I wondered why you had done it that way.
I'll spend even more time effectively diffing --help output for each subcommand and make sure they line up. I've kept parameter and argument names the same as well.
Thanks!
I could at least add some integration tests for mainline scenarios (maybe even a few corner case scenarios) and exec nbgv before and after my changes. Wouldn't hurt having those tests moving forward either to mitigate regressions.
That would be incredible. I wouldn't insist on that to complete the PR, but if you're offering, I'll gratefully accept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any particular mainline scenarios you'd like tested? Was thinking:
get-version
set-version <version>
cloud -s GitHubActions -a -c
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add
get-version -f json
and at least coverage of the variants used by the nbgv GitHub Action.
Comparing nbgv v3.3.37+0989e8fe0c to this PR, though all the options were converted from what's currently in master (note: there are existing regressions I've opened separately), the following options appear to be the same except where noted (double-dash handling, though I worked around it): -nbgv install [-p <arg>] [-v <arg>] [-s <arg>...]
- -p, --path <arg>
- -v, --version <arg>
- -s, --source <arg>...
+nbgv install [options]
+Options:
+ -p, --path <path>
+ -v, --version <version>
+ -s, --source <source>
+ -?, -h, --help -usage: nbgv get-version [-p <arg>] [--metadata <arg>...] [-f <arg>]
- [-v <arg>] [--] <commit-ish>
- -p, --project <arg>
- --metadata <arg>...
- -f, --format <arg>
- -v, --variable <arg>
- <commit-ish>
+nbgv get-version [options] [<commit-ish>]
+Arguments:
+ <commit-ish> The commit/ref to get the version information for. The default is HEAD.
+Options:
+ -p, --project <project>
+ --metadata <metadata>
+ -f, --format <json|text>
+ -v, --variable <variable>
+ -?, -h, --help -usage: nbgv set-version [-p <arg>] [--] <version>
- -p, --project <arg>
- <version>
+Usage:
+ nbgv set-version [options] <version>
+Arguments:
+ <version>
+Options:
+ -p, --project <project>
+ -?, -h, --help With -usage: nbgv tag [-p <arg>] [--] <versionOrRef>
- -p, --project <arg>
- <versionOrRef>
+Usage:
+ nbgv tag [options] [<versionOrRef>]
+Arguments:
+ <versionOrRef>
+Options:
+ -p, --project <project>
+ -?, -h, --help -usage: nbgv get-commits [-p <arg>] [-q] [--] <version>
- -p, --project <arg>
- -q, --quiet
- <version>
+Usage:
+ nbgv get-commits [options] <version>
+Arguments:
+ <version>
+Options:
+ -p, --project <project>
+ -q, --quiet
+ -?, -h, --help -usage: nbgv cloud [-p <arg>] [--metadata <arg>...] [-v <arg>] [-s <arg>]
- [-a] [-c] [-d <arg>...]
- -p, --project <arg>
- --metadata <arg>...
- -v, --version <arg>
- -s, --ci-system <arg>
- -a, --all-vars
- -c, --common-vars
- -d, --define <arg>...
+Usage:
+ nbgv cloud [options]
+Options:
+ -p, --project <project>
+ --metadata <metadata>
+ -v, --version <version>
+ -s, --ci-system
+ <AppVeyor|AtlassianBamboo|GitHubActions|GitLab|Jenkins|TeamCity|Travis|VisualStudioTeamServices>
+ -a, --all-vars
+ -c, --common-vars
+ -d, --define <define>
+ -?, -h, --help -usage: nbgv prepare-release [-p <arg>] [--nextVersion <arg>]
- [--versionIncrement <arg>] [-f <arg>] [--] <tag>
- -p, --project <arg>
- --nextVersion <arg>
- --versionIncrement <arg>
- -f, --format <arg>
- <tag>
+Usage:
+ nbgv prepare-release [options] [<tag>]
+Arguments:
+ <tag>
+Options:
+ -p, --project <project>
+ --nextVersion <nextVersion>
+ --versionIncrement <versionIncrement>
+ -f, --format <json|text>
+ -?, -h, --help Though the original usage shows |
I opened dotnet/command-line-api#1238 to track the compatibility issue. I added some middleware in the meantime to support |
All manual testing we listed worked except for |
Thank you, @heaths for this contribution. We'll follow up on the other issue(s) you filed. |
Resolves #559