Open biosmanager opened 4 years ago
Try this:
[Option("json")]
bool JsonFormat { get; set; }
[Value(0)]
string OutputFilename { get; set; }
Now --json
is a Boolean option, and whether or not it's set, OutputFilename contains the output filename (and if it's null or empty, use stdout).
BTW, why not use -
as the filename that means "standard output", the way Unix commands have done for ages? Then your options class would look like this:
[Option("json")]
bool JsonFormat { get; set; }
[Value(0, DefaultValue="-")]
string OutputFilename { get; set; }
And your code would check for the filename "-" rather than an empty string as the signal to use stdout.
I have the same question. Value is OK but then it can occur anywhere in command line like this:
MyApp -json file.json
MyApp file.json -json
MyApp -json -otheroption -anotheroption file.json
It is not even clear what this value is for. The help text for value that is not an option is quite user-unfriendly in my opinion. Having option with an optional value would be much cleaner solution.
I'm trying to implement a string option that can have three states:
I want to do the following:
MyApp.exe
writes unformatted output to standard outputMyApp.exe --json
writes JSON formatted output to standard outputMyApp.exe --json file.json
writes JSON formatted output tofile.json
Is this currently possible?