commandline
commandline copied to clipboard
Option without value should throw an error.
If I have a string option and it is called without a value, no error is thrown. This is what I would expect.
using CommandLine;
namespace cli
{
public class Program
{
static void Main(string[] args)
{
CommandLine.Parser.Default.ParseArguments<Options>(args)
.WithParsed(options => RunOptions(options))
.WithNotParsed(error => ErrorAndExit(error));
}
static void RunOptions(Options options)
{
}
static void ErrorAndExit(IEnumerable<Error> error)
{ }
}
public class Options
{
[Option("value", Required = false, HelpText = "A value.")]
public string Value { get; set; }
}
}
If i call this command line i get no error.
cli --value # should throw an error
cli --value blah # ok, this is what i want
I second this. There's no easy way of knowing whether a parameter was supplied without value or if it was omitted, and those are two different kinds of failure for us.
Why would this throw an error? You have required = false in the Option attribute...
theres a third scenario:
cli --value
cli --value blah
cli --value --othervalue
Effectively 1 and 3 are the same
Required requires the option. This has nothing todo with the requirement of an option value.
https://github.com/commandlineparser/commandline/wiki/Option-Attribute
| Required | Gets or sets a value indicating whether a command line option is required. |
|---|
A string option should also force a value as with getopt has_arg
https://man7.org/linux/man-pages/man3/getopt.3.html