Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: use '-h' for robust lefthook (Go binary) existence checking #116

Merged
merged 1 commit into from
Mar 10, 2020
Merged

Fix: use '-h' for robust lefthook (Go binary) existence checking #116

merged 1 commit into from
Mar 10, 2020

Conversation

fahrinh
Copy link
Contributor

@fahrinh fahrinh commented Mar 6, 2020

Call 'lefthook' Go binary returns failed retval because of 'subcommand is required'

How to reproduce:

$ go get github.com/Arkweid/lefthook
$ lefthook >/dev/null 2>&1
$ echo $?                                    # returns '1'
$ lefthook -h >/dev/null 2>&1
$ echo $?                                    # returns '0'

Other methods (bundle exec & npx) are fine without -h actually

@Arkweid
Copy link
Collaborator

Arkweid commented Mar 6, 2020

Thanks for PR @fahrinh
Intresting, what OS do you have?

@fahrinh
Copy link
Contributor Author

fahrinh commented Mar 8, 2020

Thanks for PR @fahrinh
Intresting, what OS do you have?

macOS Mojave 10.14.6
ZSH 5.8

I think it's how spf13/cobra works. If rootCmd has not provided with 'Run', a subcommand is required (source)

Lefthook (Go binary) without subcommand:

It returns exit code 1

$ ~/go/bin/lefthook
After installation go to your project directory
and execute the following command:
lefthook install

Usage:
  lefthook [command]

Available Commands:
  add         This command add a hook directory to a repository
  help        Help about any command
  install     Write basic configuration file in your project repository. Or initialize existed config
  run         Execute group of hooks
  uninstall   Revert install command
  version     Show lefthook version

Flags:
  -a, --aggresive   remove all hooks from .git/hooks dir and install lefthook hooks
  -f, --force       reinstall hooks without checking config version
  -h, --help        help for lefthook
      --no-colors   disable colored output
  -v, --verbose     verbose output

Use "lefthook [command] --help" for more information about a command.
2020/03/08 15:54:52 subcommand is required

Lefthook (Go binary) with subcommand (-h for example):

It returns exit code 0

$ ~/go/bin/lefthook -h
After installation go to your project directory
and execute the following command:
lefthook install

Usage:
  lefthook [command]

Available Commands:
  add         This command add a hook directory to a repository
  help        Help about any command
  install     Write basic configuration file in your project repository. Or initialize existed config
  run         Execute group of hooks
  uninstall   Revert install command
  version     Show lefthook version

Flags:
  -a, --aggresive   remove all hooks from .git/hooks dir and install lefthook hooks
  -f, --force       reinstall hooks without checking config version
  -h, --help        help for lefthook
      --no-colors   disable colored output
  -v, --verbose     verbose output

Use "lefthook [command] --help" for more information about a command.

Lefthook (Ruby, gem) without subcommand:

It returns exit code 0

$ ~/.rvm/gems/ruby-2.6.3/bin/lefthook
/Users/fahrihidayat/.rvm/gems/ruby-2.6.3/gems/lefthook-0.7.1/libexec/lefthook-mac
After installation go to your project directory
and execute the following command:
lefthook install

Usage:
  lefthook [command]

Available Commands:
  add         This command add a hook directory to a repository
  help        Help about any command
  install     Write basic configuration file in your project repository. Or initialize existed config
  run         Execute group of hooks
  uninstall   Revert install command
  version     Show lefthook version

Flags:
  -a, --aggresive   remove all hooks from .git/hooks dir and install lefthook hooks
  -f, --force       reinstall hooks without checking config version
  -h, --help        help for lefthook
      --no-colors   disable colored output
  -v, --verbose     verbose output

Use "lefthook [command] --help" for more information about a command.

@Arkweid Arkweid merged commit 5691e6d into evilmartians:master Mar 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants