GithubHelp home page GithubHelp logo

Comments (13)

c-blake avatar c-blake commented on June 18, 2024 1

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.

c-blake avatar c-blake commented on June 18, 2024

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.

c-blake avatar c-blake commented on June 18, 2024

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.

timotheecour avatar timotheecour commented on June 18, 2024

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.

timotheecour avatar timotheecour commented on June 18, 2024

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.

timotheecour avatar timotheecour commented on June 18, 2024

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 case height argument is later added
  • it makes for more uniform command line interfaces (-h predictably means --help)

from cligen.

timotheecour avatar timotheecour commented on June 18, 2024

right sorry :-) ; just fixed typo above

from cligen.

c-blake avatar c-blake commented on June 18, 2024

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.

timotheecour avatar timotheecour commented on June 18, 2024

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.

c-blake avatar c-blake commented on June 18, 2024

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.

c-blake avatar c-blake commented on June 18, 2024

locate --regex '/-.$' turns up nothing for me on my system, but it is definitely imaginable.

from cligen.

timotheecour avatar timotheecour commented on June 18, 2024
  • 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.

c-blake avatar c-blake commented on June 18, 2024

Closed by d21fd35

from cligen.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.