gsscoder / commandline

Terse syntax C# command line parser for .NET with F# support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use Verbs in combination with inheritance?

dasdingo opened this issue · comments

When trying to have 2 verbs which inherit from a base class i get the following error:

System.InvalidOperationException: Sequence contains more than one matching element

at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable1 source, Func2 predicate)
at CommandLine.Core.TypeLookup.GetDescriptorInfo(String name, IEnumerable1 specifications, StringComparer comparer) at CommandLine.Core.InstanceBuilder.<>c__DisplayClass161.b__8(String name)
at CommandLine.Core.TokenPartitioner.<>c__DisplayClass10.b__e(Token t)
at System.Linq.Enumerable.WhereListIterator1.MoveNext() at System.Collections.Generic.List1..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at CommandLine.Core.TokenPartitioner.Partition(IEnumerable1 tokens, Func2 typeLookup)
at CommandLine.Core.InstanceBuilder.Build[T](Func1 factory, Func3 tokenizer, IEnumerable1 arguments, StringComparer nameComparer, CultureInfo parsingCulture) at CommandLine.Parser.<>c__DisplayClass41.b__2()
at CommandLine.Parser.MakeParserResult[T](Func1 parseFunc, ParserSettings settings) at CommandLine.Parser.ParseArguments[T](Func1 factory, String[] args)
at CommandLine.Parser.ParseArguments[T](String[] args)
at HnnsEcuDevel2.HnnsCommandLineParser.ParseCommands(String[] args) in c:\ekk_Gen4_Dev\20_branches\10_dev\dschmitt\HV_0v9r2\23_SW_Implementation\23c_Application\matlab_target\HnnsEcuDevel2\HnnsEcuDevel2\HnnsCommandLineParser.cs:line 26
at HnnsEcuDevel2.HnnsCommandLineParser.ParseCommands(IList`1 args) in c:\ekk_Gen4_Dev\20_branches\10_dev\dschmitt\HV_0v9r2\23_SW_Implementation\23c_Application\matlab_target\HnnsEcuDevel2\HnnsEcuDevel2\HnnsCommandLineParser.cs:line 49
at HnnsEcuDevel2.Program.Main(String[] args) in c:\ekk_Gen4_Dev\20_branches\10_dev\dschmitt\HV_0v9r2\23_SW_Implementation\23c_Application\matlab_target\HnnsEcuDevel2\HnnsEcuDevel2\Program.cs:line 35

Is inheritance of option classes not supported at the moment?

commented

Can you post the relevant options classes? Quick glance says you might be duplicating verb names in the child class, but it's hard to tell without a sample.

Code Extract:
Baseclass:
public class CommandLineOptions
{

	[Option('m', "ma", Min = 3,Max = 3, HelpText = "[]")]
	public IEnumerable<string> InputTypes { get; set; }
    }

child class:

public class ListGeneratorCommandLineOptions : CommandLineOptions
{
public enum GenType
{
dat
}

	[Option('g', "gentype", Required=true, HelpText = "File Generation.")]
	public GenType GenerationType { get; set; }

In Main:

var result = Parser.Default.ParseArguments(args);

commented

What version of the library? I'm using the latest beta and it works fine (although you need to explicitly specify the options type you are parsing: Parser.Default.ParseArguments<ListGeneratorCommandLineOptions>(args))

I used version 2.0.0.0 before. Now I am using 2.0.275.0 and everything works fine! Thank you very much!