Skip to content

[system-command-line] replaced host and telemetry logger parameters to NewCommand with delegates - #4254

Merged
vlada-shubina merged 3 commits into
dotnet:feature/system-command-linefrom
vlada-shubina:binding
Jan 14, 2022
Merged

[system-command-line] replaced host and telemetry logger parameters to NewCommand with delegates#4254
vlada-shubina merged 3 commits into
dotnet:feature/system-command-linefrom
vlada-shubina:binding

Conversation

@vlada-shubina

@vlada-shubina vlada-shubina commented Jan 12, 2022

Copy link
Copy Markdown
Member

SDK (and also dotnet new3) needs to read some of the args to build the host.
In dotnet new3 this was solved via "pre-parsing" which was not ideal solution. Doing similar thing in SDK is not a way to go.

I have replaced host and telemetryLogger parameters with `Func<ParseResult, T> delegates to be able to create those once parsing is done. This way SDK may define additional options, add them to command and use them when creating hosts in this delegates.

Check the adaptation of dotnet new3 code to see how it works.

This revealed a problem when moving from dotnet new to instantiate command and manually adding global options to each BaseCommand. --debug: options were moved as GlobalOption on in NewCommand now. Also added tests for --debug: options.

fixes #3812
fixes #3053

@baronfel

Copy link
Copy Markdown
Member

That looks pretty straightforward to consume. It's essentially taking the same logic that's inside the Binder I made in my PR for the new Command, so it should be easy to extract that and be good to go 👍


commandResult
.Should()
.Fail()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unrelated to this PR: why do we fail when we try to list 0 templates? Sounds like list command executed successfully here.

Comment thread src/Microsoft.TemplateEngine.Cli/NewCommandFactory.cs Outdated
Comment thread src/Microsoft.TemplateEngine.Cli/TemplateListCoordinator.cs Outdated
Comment thread src/Microsoft.TemplateEngine.Cli/Commands/alias/AliasCommand.cs Outdated
Comment thread src/Microsoft.TemplateEngine.Cli/Commands/NewCommand.Legacy.cs Outdated
Comment thread src/Microsoft.TemplateEngine.Cli/Commands/BaseCommand.cs

@DavidKarlas DavidKarlas left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cool, after inspecting calls to CreateTelemetryLogger and CreateEnvironmentSettings looks like we dont need to do any caching...

@vlada-shubina
vlada-shubina merged commit cce5fc2 into dotnet:feature/system-command-line Jan 14, 2022
@vlada-shubina
vlada-shubina deleted the binding branch January 14, 2022 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Tab Completion] Move global options to new command line parser add tests for debug: arguments to dotnet.new3.UnitTests

4 participants