Replies: 1 comment
-
I would also be interested in this topic. Here is my use case: We use Spectre in two ways - one is to execute commands quickly, and another is to write some commands in the form of test files.
To use @schallm's example, writing and executing I know this use case might sound like a first world problem, but it's one of those QoL features that really stands out once you are accustomed to it. As a third possibility to the proposal, it could be a completely new attribute, instead of a modification to the existing A workaround could be making a command that takes both a public class MySettings : CommandSettings
{
[CommandArgument(0, "[name]")] // using <name> would cause an error when the command is invoked with the optional argument.
public string Name { get; init; }
[CommandOption("-n|--name [name]")]
public string NameOpt { get; init; }
public MySettings (string name, string nameOpt)
{
this.Name = name;
if (string.IsNullOrEmpty(this.Name))
{
this.Name = nameOpt;
}
// Do we assign NameOpt at all?
}
} I would love to contribute on this, should it be considered worthy. |
Beta Was this translation helpful? Give feedback.
-
When specifying command line arguments, I like PowerShell's approach were you can always specify the name of the argument at the command line. As commands get more arguments position alone starts to break down. It also makes scripts more self documented.
I can then from the command line type
Get-ChildItem C:\Temp\ *.csv
orGet-ChildItem -Path C:\Temp\ -Filter *.csv
. This is a trivial example, but even for something this simple , I think the second is far more readable. Some commands will be far more complex with more required arguments. Ensuring you get them in the correct order seems error prone.I have not found anyway to do this, but is it currently possible to include the name a
CommandArgument
at the command line. Alternatively, is there way way to require aCommandOption
?Something like the following?
or
Beta Was this translation helpful? Give feedback.
All reactions