gsscoder / commandline

Terse syntax C# command line parser for .NET with F# support
1.63k stars 293 forks source link

Is it possible to have a property as part of multiple sets? #274

Open ravensorb opened 8 years ago

ravensorb commented 8 years ago

Consider the following idea below.

It is setup to have 2 properties that can always be supplied (Start/End Date), one property that can be supplied with the "file" and the "filter1" set, and then 1 property for the "filter1", 1 property for the "filter2" and 1 property for the "file" set. Is this possible?

public class Opts1
{
    [Option('s')]
    public DateTime StartDate {get; set;}
    [Option('e')]
    public DateTime EndDate {get; set; }

    [Option('n', SetName = "file;filter1")]
    public string Name { get; set;}

    [Option('a', SetName = "filter1")]
    public int Age { get; set; }

    [Option('i', SetName = "filter2")]
    public string ID { get; set;}

    [Option('f', SetName = "file")]
    public string InputFile {get; set;}
}
alexanderfast commented 8 years ago

Hm, I'm not sure I correctly understand what you mean. Could you provide the actual command line for your examples? And the resulting property values?

ravensorb commented 8 years ago

Sure. Below are a few example permutations.

If you look at the class above, "n" can be used with both "f" and "a" however "f" can ONLY be used with "n", if "f", "a", and "n" were used it would be invalid. This results in valid combinations of "f" and "a" or "f" and "i".

Valid:

Invalid

The value of this is allow certain properties to be used across multiple sets while still apply some sort of scope to them so that they cannot be used across ALL scopes.

Does that help?

alexanderfast commented 8 years ago

Yes that makes it clearer. I was hoping we could use the MutuallyExclusive setting, but this relationship is more complex. I think your best bet is to check this yourself after parsing is completed. But these rules might also be tricky to adequately explain to your users. Maybe split it up into several verbs with similar options?

ravensorb commented 8 years ago

The 2nd is what I am doing now -- the hard part is it requires a LOT of duplicate properties with slightly different names which makes the code complex in using the various options class.

In the example above you'd end up with Name and NameWithFileName, Age and AgeWithFileName and then you would have "FileName" in both of the verb classes.

cspaniard commented 8 years ago

Hi, I also would need this functionality. It would really make the options relate one to another more directly, avoiding boilerplate code.