Tyrrrz/CliFx

Is there something like optional parameter?

davidsalb opened this issue · 3 comments

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.

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.

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.

You're welcome!