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

Ability to add command line flags and their values to remaining arguments if they cannot be set on the settings class #1059

Closed
FrankRay78 opened this issue Nov 9, 2022 · 0 comments · Fixed by #1103

Comments

@FrankRay78
Copy link
Contributor

FrankRay78 commented Nov 9, 2022

Is your feature request related to a problem? Please describe.
There is an open issue in the cake project, cake-build/cake#3279, which has been triaged and accepted as an improvement, to 'Allow users to use any of the Cake runner arguments as build script arguments'

An example of what this practically means is as follows. Here is a flag currently defined on the cake DefaultCommandSettings class:

        [CommandOption("--version|--ver")]
        [Description("Displays version information.")]
        public bool ShowVersion { get; set; }

And normally the user would invoke this by dotnet cake --version.

However, sometimes the user would like to specify a version number and have it pass to their build script instead. Currently they must write dotnet cake -- --version=1.2.3 to explicitly ensure the version number is parsed as a remaining argument, not a command setting.

The above issue, cake-build/cake#3279, would allow dotnet cake --version=1.2.3 to add version=1.2.3 to the remaining arguments list, and dotnet cake --version to set the ShowVersion property to true (ie. continue operating as current).

Describe the solution you'd like
A configuration setting that informs the command parsing logic to catch any exceptions thrown when setting values on the command settings class (eg. Flags cannot be assigned a value.) and instead add the option and its value to the remaining arguments list. This configuration setting could be turned off as a default to ensure backward compatibility with existing behaviour.

(This solution depends on #1048 being merged, so that command options (and their values) work nicely ahead of any arguments)

Describe alternatives you've considered
Should this feature be deemed as not viable for spectre.console for any reason, I would look to see how the exception could be caught higher up in the cake codebase, and/or some kind of extension point being opened within the command parsing logic perhaps. And then subsequently some way to inject the caught value back into the remaining args from the cake codebase [pretty ugly sounding]. I think, however, the solution proposed above is a clean and generic improvement to spectre console whilst also preserving existing behaviour.

nb. please assign the issue to me @patriksvensson if it successfully makes it out of triage 🙂

@FrankRay78 FrankRay78 changed the title Ability to add command line values to remaining arguments if they cannot be set on the settings class Ability to add command line flags and their values to remaining arguments if they cannot be set on the settings class Nov 10, 2022
@FrankRay78 FrankRay78 self-assigned this Dec 11, 2022
@FrankRay78 FrankRay78 linked a pull request Dec 11, 2022 that will close this issue
patriksvensson pushed a commit that referenced this issue Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done 🚀
Development

Successfully merging a pull request may close this issue.

1 participant