This repository was archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 161
Use System.CommandLine.Experimental instead of NDesk.Options #347
Merged
laedit
merged 65 commits into
Code52:master
from
biohazard999:topic/System.CommandLine.Experimental-346
Oct 8, 2019
Merged
Use System.CommandLine.Experimental instead of NDesk.Options #347
laedit
merged 65 commits into
Code52:master
from
biohazard999:topic/System.CommandLine.Experimental-346
Oct 8, 2019
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dotliquid sorting (Code52#325)
…dLine.Experimental-346
Contributor
|
Thanks a lot for your hard work! |
laedit
reviewed
Sep 30, 2019
Contributor
|
So sorry that it took me so long, but I needed to try some things about |
laedit
suggested changes
Oct 5, 2019
laedit
reviewed
Oct 6, 2019
laedit
reviewed
Oct 6, 2019
laedit
reviewed
Oct 8, 2019
laedit
approved these changes
Oct 8, 2019
Contributor
|
We have finally pulled this through! |
Contributor
Author
🎉🥳
It's totally fine! Nothing to worry about 😁 A couple more PR's and we have a nice dotnet global tool 🥰 |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #346
This is a major breaking change.
This PR replaces
NDesk.Optionswith Microsoft's newSystem.CommandLine.Experimental.Cause they are fundamentally different in architecture there are some key gotchas to the whole startup architecture as well as argument handling.
Motivation
Before all commands shared a
BaseParametersandCommandParametersclass as well as theIHaveCommandLineOptionsfor extentions to provide custom arguments.This changed fundamentally. Every command has it's own command line arguments. It is extensible via the
CommandArgumentsExtentionAttributeandIHaveCommandLineArgsexports and interfaces.Example for a new command:
CommandInfo.CommandNamemust matchCommandArguments.CommandNameto get hooked together.To reduce risk of failure the
BuiltInCommandsclass was introduced.Every command that need's site context can use
PretzelBaseCommandParametersas a base for the parameters. For extendable parameters authors can useBaseParametersas a base class. For complete control plugin authors can implementICommandParametersandICommandParametersExtendableon their own.Plugin authors that need custom arguments for an command
Author's can extend multiple commands at once by using multiple command names:
The implementation keeps the same except for they just import their new parameters
New application startup
We use an separate RootCommand to provide the 3 parameters used in startup (majorly plugin discovery). Those get's injected afterwards into the actual rootcommand/subcommands after MEF kicked in. This way we get the benifit of having help available even if MEF discovery should fail in some sort of way. Attributes are processed before the actual command instance get's created. This way separate commands can't break the whole application if MEF binding will fail (at least for the commands, arguments are a different story).
The Logic from
BaseParameters.SetPathmoved toProgram. Afterward's the-sparameter will be set. This way the value is correct before it hit's the arguments parsing. I think this simplifies the overall design of the system.The reason for this parameter is: we can start pretzel with
pretzel bake c:\foo\mybloghence no breaking change for pretzel consumers. There is probably a better way of solving this problem in theSystem.CommandLinelibrary, but couldn't figure out how 🤷♂️.Architectural questions that need to be discussed
Pretzeland should the parameters life there as well (or should we move them toPretzel.Logic.If not, how should plugin authors get needed parameters? We could for example double bind parameters (just use the same names as in the pretzel build in ones), but that could be error prown cause of the modifications that can be made inBindingComplete. Exporting for example theIBakeCommandParameterswould be easy and intuitive.ReadFromFilemethod public, this way we get rid of the [Import("SourcePath")] and get a lot nicer lifecycle. It's now 100% clear when configuration get's read. So no weird side effects ifIConfigurationget's read to early in the MEF lifecycle.IHaveCommandLineArgshas a weird name. Probably we should rename it toICommandArgumentsExtentionthat way it would match the attributeCommandArgumentsExtentionAttributeTaskbut i think it would be befinitial to change it toTask<int>to support error codes, if we change it anyway.Parameters.Pathin favor of theParameters.SourceandParameters.Destinationproperties, cause I think it's much clearer what path we are talking about. It's now also consistent with the command line parameter name.Things that need to be done before merging
Program.cs@laedit as always, would be cool if you got an early eye on this. I think this layes out a good foundation for the future of 🥨 ❤
This is an opener for #146