question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Command w/o args displaying usage should return non-zero

See original GitHub issue

Try running git, and you will see its usage. You will also receive a non-zero return code, indicating failure. This can be vital in case arguments got truncated.

Current behavior of showing usage instructions (help_text) is great!

But it should also error out with a code 1.

Example:

➜  git
usage: git [--version] [--help] [-C <path>] [-c <name>=<value>]
           [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
           [-p | --paginate | --no-pager] [--no-replace-objects] [--bare]
           [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
           <command> [<args>]

(snip)

'git help -a' and 'git help -g' list available subcommands and some
concept guides. See 'git help <command>' or 'git help <concept>'
to read about a specific subcommand or concept.
➜  echo $?
1

Reference: https://github.com/learningequality/kolibri/pull/5937

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
laydaycommented, Oct 7, 2019

This only happens with groups - invoking a (sub-)command requiring arguments, without arguments, will raise and exit with a non-zero status code. The default behaviour of a group is not to call the callback (i.e. the wrapped function) if the argument is not supplied, which presupposes that it is required. Click should exit with a non-zero status code if invoke_without_command is false and defer to the callback if it’s true.

1reaction
benjaomingcommented, Sep 16, 2019

@davidism

so I don’t currently see a compelling reason to change this

mycommand $filename <= if $filename is empty by mistake, then it will return 0 as if execution was successful.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python: get output from a command line which exits with ...
I'm trying to get the output of a command line process which gives a nonzero exit status after outputting the information I need....
Read more >
subprocess — Subprocess management — Python 3.11.1 ...
Run the command described by args. Wait for command to complete, then return a CompletedProcess instance. The arguments shown above are merely the...
Read more >
Bash command line exit codes demystified | Enable Sysadmin
To display the exit code for the last command you ran on the command line, use the following command: $ echo $?.
Read more >
xargs - Construct an argument list and run a command - IBM
The xargs command line typically contains the skeleton, ... it should explicitly contain an exit command to avoid returning a nonzero by accident; ......
Read more >
Batch Script - Return Code - Tutorialspoint
Batch Script - Return Code, By default when a command line execution is completed it should either return zero when execution succeeds or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found