This repository has been archived by the owner on Jun 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 163
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 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
Thanks a lot for your hard work! |
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
We have finally pulled this through! |
🎉🥳
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.Options
with 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
BaseParameters
andCommandParameters
class as well as theIHaveCommandLineOptions
for extentions to provide custom arguments.This changed fundamentally. Every command has it's own command line arguments. It is extensible via the
CommandArgumentsExtentionAttribute
andIHaveCommandLineArgs
exports and interfaces.Example for a new command:
CommandInfo.CommandName
must matchCommandArguments.CommandName
to get hooked together.To reduce risk of failure the
BuiltInCommands
class was introduced.Every command that need's site context can use
PretzelBaseCommandParameters
as a base for the parameters. For extendable parameters authors can useBaseParameters
as a base class. For complete control plugin authors can implementICommandParameters
andICommandParametersExtendable
on 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.SetPath
moved toProgram
. Afterward's the-s
parameter 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\myblog
hence no breaking change for pretzel consumers. There is probably a better way of solving this problem in theSystem.CommandLine
library, but couldn't figure out how 🤷♂️.Architectural questions that need to be discussed
Pretzel
and 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 theIBakeCommandParameters
would be easy and intuitive.ReadFromFile
method 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 ifIConfiguration
get's read to early in the MEF lifecycle.IHaveCommandLineArgs
has a weird name. Probably we should rename it toICommandArgumentsExtention
that way it would match the attributeCommandArgumentsExtentionAttribute
Task
but i think it would be befinitial to change it toTask<int>
to support error codes, if we change it anyway.Parameters.Path
in favor of theParameters.Source
andParameters.Destination
properties, 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