Tyrrrz / CliFx

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

Is there something like optional parameter? #76

Closed davidsalb closed 4 years ago

davidsalb commented 4 years ago

I am writing a tool to manage xml files. I already implemented a show command which gives me the value of a speciefied key. Like:

$ myapp show Name >Value of 'Name': Paul

Now I want it to give me all attributes if no key is provided. Like:

$ myapp show *prints all the fields.*

As far as I can tell paramters are always required? My current approach is using * as key-parameter but that's not really what i want. (myapp show *)

Sorry if the answer to this question is obvious but I couldn't find a sample for that use case.

Thanks in advance.

Tyrrrz commented 4 years ago

Hi.

Indeed, parameters are always required. This is explained in the readme here (scroll to "Overall, the difference between parameters and options is as follows").

The reason is mostly design. If you have multiple optional parameters, it's really hard to determine (and sometimes impossible) what gets set to what.

Instead, if you need an optional argument, you should use an option.

davidsalb commented 4 years ago

So I will probably do something like:

$ myapp show --key Name Value of 'Name': Paul

and the default without an argument will print it all.

This can be closed. Thanks for the answer.

Tyrrrz commented 4 years ago

You're welcome!