You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Let long/short argument options be atoms (or error out) #22
Of course, it works if I change it to $b. This one took a long time to debug 😄
If they should take atoms, I think short should only take one letter atoms and error out otherwise, and long should take any string atom and automatically prepend it with "-" so that the default flag format is --flag (since most UNIX CLIs follow that).
I dug into this specific issue and found that argparse already throws when short is not a printable character, or long is not a printable string.
Now what's been happening with cli, it was catching this exception, and printing this to Erlang Logger:
This is a deliberate decision, to keep running cli even when some command has invalid description, and just log instead. The reason is, we often have dozens and even hundreds of modules exporting cli, and it happens that some commands may have a broken description, or something else broken. Therefore we cannot fail the entire cli, and have to ignore the malformed command.
I understand that this behaviour is not exactly useful for smaller projects. What I think of, there is warn option available for cli:run/2, that can be set to warn (default meaning "print the discovered issue to logger") and suppress (silently ignore). I can add another value, halt, that would mean "print the problem to stdout and halt the VM".
Another clue is given by Dialyzer, it immediately warns against atoms set as short or long attributes. It might be enough signal to figure out the invalid argument description.
Activity
max-au commentedon Mar 13, 2022
I dug into this specific issue and found that
argparsealready throws whenshortis not a printable character, orlongis not a printable string.Now what's been happening with
cli, it was catching this exception, and printing this to Erlang Logger:This is a deliberate decision, to keep running
clieven when some command has invalid description, and just log instead. The reason is, we often have dozens and even hundreds of modules exportingcli, and it happens that some commands may have a broken description, or something else broken. Therefore we cannot fail the entire cli, and have to ignore the malformed command.I understand that this behaviour is not exactly useful for smaller projects. What I think of, there is
warnoption available forcli:run/2, that can be set towarn(default meaning "print the discovered issue to logger") andsuppress(silently ignore). I can add another value,halt, that would mean "print the problem to stdout and halt the VM".max-au commentedon Mar 13, 2022
Another clue is given by Dialyzer, it immediately warns against atoms set as
shortorlongattributes. It might be enough signal to figure out the invalid argument description.