Tyrrrz / CliFx

Class-first framework for building command-line interfaces
MIT License
1.48k stars 60 forks source link

Allow for minimum number of items in array-backed parameters #65

Closed Merlin04 closed 4 years ago

Merlin04 commented 4 years ago

When I have a parameter like this:

[CommandParameter(0)]
public FileInfo File { get; set; }

And I don't pass in a file, the program display the help message. However, if I make that a list:

[CommandParameter(0)]
public IReadOnlyList<FileInfo> Files { get; set; }

And don't pass in any files, the command runs. It would be really helpful to be able to specify that the parameter needs to have at least one file.

ADustyOldMuffin commented 4 years ago

I'm interested in taking this on as I'd like to start contributing if that's alright.

Tyrrrz commented 4 years ago

Sure thing. If you want, you can outline how you're planning to approach this and we can discuss it. Or you can just make a PR and we'll take it from there.

ADustyOldMuffin commented 4 years ago

Give me a chance to take a gander through the source and I'll post here my idea and see if that'll work and then I'll try to hack it out.

ADustyOldMuffin commented 4 years ago

@Tyrrrz So for the implementation it would require adding optional parameter of MinimumSize or something of the sort with a default of 0. If this is specified and greater than 0 then it would validate this in ValidateParameters. You could also add to the analyzer that if the value for minimum is larger than 1 then the expected size for the parameter is a collection.

Let me know your thoughts and if I'm way off base.

Tyrrrz commented 4 years ago

I think you can just rely on IsRequired parameter. If it's set, having 0 items is invalid.