commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Add support for multicharacter short option

Open alexxn opened this issue 8 years ago • 4 comments

Sometime it is usefull to have not only single char short option like [Option('d', "download-file")] but something like [Option('gf', "graph-file")].

This is not a common approach, but might be needed for compatibility of command line parameters with other products.

alexxn avatar Mar 27 '17 16:03 alexxn

I'm in favor of this as well. Just a side note though, it would probably be more like [Option("gf", "graph-file")] as C-like languages use single quotes for the char type which can only take one character unless an array is used.

XenHat avatar Mar 27 '17 20:03 XenHat

This is not going to happen with short options - short options must be a single character only. This conforms to the standard UNIX getopt format. commandline also allows bundling of short options so -gf is functionally equivalent to -g -f. What are your thoughts on an alias for long options (so --graph-file and --gf are equivalent)?

Example of short arg bundling:

void Main()
{
	Parser.Default.ParseArguments<Options>("-lgn Arnold".Split())
	.WithParsed(o => o.Dump())
	.WithNotParsed(e => e.Dump());
}

public class Options
{
	[Option('l', "logging")]
	public bool Logging { get; set; }

	[Option('g', "graphics")]
	public bool Graphics { get; set; }

	[Option('r', "realtime")]
	public bool Realtime { get; set; }

	[Option('n', "name")]
	public string Name { get; set; }
}

nemec avatar Mar 27 '17 21:03 nemec

Aliases is also a very handy feature.

alexxn avatar Mar 27 '17 22:03 alexxn

Alias would be handy, indeed. it would simplify backward-compatibility for me.

XenHat avatar Mar 28 '17 09:03 XenHat