Comments (13)
The error code is trivial to bypass if you are in a script, just ignore it or suppress it like command -. || :
, but it prints out an error message about a bad option key, too. Anyway, I said I'd do this one no problem. Probably tomorrow.
I am a bit confused by your very last comment, though. It seems like your option 2 would break scripts when height
is added later and you want -h
to stay help
. So, maybe you just meant to say you strongly preferred option 1.
from cligen.
Specifying any non-existent short option also gets you a help message. There is no way for '.'
to be an option in cligen
(since you can't have a variable named '.'
, but often just because no one ever does..). So, I usually just type "command -."
.
That being said, it would be super easy to just add yet another defaulted argument to the macros shortHelp='h'
or shortHelp='?'
and check for the collision, giving priority to user shortKeys over this system generated one as you suggest. I chose '?'
just to avoid that minor hassle.
from cligen.
Also, I haven't specifically tested it, but I bet there's some problem if the wrapped proc
has a named parameter called "help"
. So, it might be best to take the long/short pair as an argument defaulting to ("help", 'h'), at least allowing things to run in such a case. Of course, if --help
doesn't print a help message, users will complain.
from cligen.
Specifying any non-existent short option also gets you a help message
-.
will print help but return an error code so behaves differently from-h
in scripts
from cligen.
Also, I haven't specifically tested it, but I bet there's some problem if the wrapped proc has a named parameter called "help"
proc foobar2(help="foo"): int = 0
gives Error: duplicate case label
In this particular case that's fine I think, it is a rare corner case
from cligen.
not 100% sure what you're suggesting as best course of action above, but IMO we should have sane defaults, ie -h
--help
for help when dispatch(foo)
is called, because most users will call dispatch with no other arguments. It results in more uniformity in cmd line interfaces generated by cligen.
A user can always override behavior if he needs to.
I think there should be 2 options for default behavior when an argument starts with h
(eg height
)
- option 1:
-h, --help
--height=
- option 2:
--help
-h=,--height=
I strongly prefer option 1 because: EDIT:fixed typo 2=>1
- it won't break scripts (that call
./app -h
) in caseheight
argument is later added - it makes for more uniform command line interfaces (
-h
predictably means --help)
from cligen.
right sorry :-) ; just fixed typo above
from cligen.
Gotcha Re: typo. And to clarify, I was just proposing we let the user choose the character, 'h'
, '?'
, whatever.
As to which is the most sane default, I don't know. -h
is more common (but not nearly as universal as --help
).
OTOH, it's also a burden on lazy users to get them to read "if you ever think you might want a long key starting with an 'h' maybe you should override the default". My initial thinking with -?
was that it's easy, too and won't ever collide with user keys. You don't usually need to quote it - only if there might be a file that matches that glob pattern. While that's not impossible, it's pretty rare in directories in my experience.
I do not know, but I would hope that the most common usage for the call to dispatch will be dispatch(myproc, help = { ... } )
. Maybe with your programs it would always have a helpShort='h'
, too, or maybe with mine always a helpShort='?'
. Honestly, no short option key for --help
is also a possibility. I've seen programs like that.
from cligen.
You don't usually need to quote it - only if there might be a file that matches that glob pattern. While that's not impossible, it's pretty rare in directories in my experience.
that's shell specific. eg for me:
./app -?
zsh: no matches found: -?
from cligen.
I use Zsh, too, but I run: unsetopt NOMATCH
in my ~/.zshenv
.
I agree it can be dangerous, though. Some file called -r
could activate recursion or something.
from cligen.
locate --regex '/-.$'
turns up nothing for me on my system, but it is definitely imaginable.
from cligen.
-
well even if it doesn't hit a file, it changes behavior in scripts (by returnining error code !=0); so can cause trouble. What's worse is it causes trouble depending on user's environment eg ~/.zshenv or user shell (eg in my case but not yours). That's a bad thing, when you ship something and it bugs only on some client's machines. If cligen is to be used for more nim tools (as I hope! it's amazing :) ) , likelihood of this increases
-
i've updated top-level msg with a few more commands that understand
-h
; basically a lot of nim cmd line tools already understand-h
from cligen.
Closed by d21fd35
from cligen.
Related Issues (20)
- Unhelpful compilation error when "short" param name is given as string HOT 5
- `parseHelps` fails on a single element HOT 6
- FR: Display textual representations of available enum values in the `clValType` column HOT 9
- How do I make global options? HOT 14
- [Bug] nim 1.0.6/1.4.8 doesn't have isNaN/isnan HOT 3
- How to use `--version`? HOT 4
- truncate default args in help menu HOT 5
- Sharing param help messages between commands HOT 2
- Some tiny remarks HOT 1
- Removing entries from a seq results in a non-zero exit HOT 10
- Setting `clCfg.helpSyntax = ""` doesn't prevent inclusion of the syntax into the binary HOT 15
- No error for passing non-static table to `help` or `short` of `dispatch` HOT 1
- No interpolation of const values in a literal passed to `help` or `short` of `dispatch` HOT 9
- [Feature request] Support for std/options HOT 7
- Sync `clCfg.version` with package HOT 3
- turning off prefix completion? HOT 14
- How to bold usage and clCfg.useHdr text from code? HOT 16
- `--help` on the multicommand programs without the command should at least list the available commands HOT 13
- "Bad enum value" response starts to and then doesn't list alternatives to the empty string HOT 2
- `strUt` requires Nim 1.2+ HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cligen.