jawher / mow.cli

A versatile library for building CLI applications in Go
MIT License
872 stars 55 forks source link

Provide more specific parsing error feedback #84

Open silasdavis opened 5 years ago

silasdavis commented 5 years ago

Currently if the FSM cannot navigate the command line options you just get an Error: incorrect usage message printed followed by the usage. With a large command this is not very helpful. It seems like mow.cli with its FSM is in a good position to give a helpful message.

It would also be useful to just echo back the verbatim command args in case on an error in case it is obvious the mistake you have made such as an $UNSET_VARIABLE in a script.

I would be interested in tackling this if you think it is a good idea and can give some guidance on how you think it would be best implemented.

What I have in mind is an output that attempts to draw a text cursor at the point of the parsing error.

jawher commented 5 years ago

This might be trickier than expected: when the FSM finally gives up, it could have traversed multiple different routes, with backtracking, so three isn't necessarily a single path you could use to construct the error message and pin point the problematic location.

Maybe the longest path, i.e. the one that matched most of the input, could be used for the error message, but I'm not sure that's necessarily the most helpful one.

I'll think some more on this, and try and come up with some examples to illustrate the problem.