From ffe81836a15effdc5d46522817eeaf55903e56c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 7 Apr 2024 22:22:00 +0000 Subject: [PATCH] fix: command argument count validations --- cmd/add.go | 2 +- cmd/dump.go | 1 + cmd/install.go | 1 + cmd/uninstall.go | 1 + cmd/version.go | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) diff --git a/cmd/add.go b/cmd/add.go index a5367a15..ad3f1f16 100644 --- a/cmd/add.go +++ b/cmd/add.go @@ -30,7 +30,7 @@ func newAddCmd(opts *lefthook.Options) *cobra.Command { Long: addDoc, Example: "lefthook add pre-commit", ValidArgsFunction: addHookCompletions, - Args: cobra.MinimumNArgs(1), + Args: cobra.ExactArgs(1), RunE: func(_cmd *cobra.Command, hooks []string) error { args.Hook = hooks[0] return lefthook.Add(opts, &args) diff --git a/cmd/dump.go b/cmd/dump.go index a8a49f25..e0071fc3 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -13,6 +13,7 @@ func newDumpCmd(opts *lefthook.Options) *cobra.Command { Short: "Prints config merged from all extensions (in YAML format by default)", Example: "lefthook dump", ValidArgsFunction: cobra.NoFileCompletions, + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { lefthook.Dump(opts, dumpArgs) }, diff --git a/cmd/install.go b/cmd/install.go index eb365e22..f27dbf5e 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -14,6 +14,7 @@ func newInstallCmd(opts *lefthook.Options) *cobra.Command { Use: "install", Short: "Write basic configuration file in your project repository. Or initialize existed config", ValidArgsFunction: cobra.NoFileCompletions, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _args []string) error { return lefthook.Install(opts, force) }, diff --git a/cmd/uninstall.go b/cmd/uninstall.go index 901ca575..7b3cdee7 100644 --- a/cmd/uninstall.go +++ b/cmd/uninstall.go @@ -13,6 +13,7 @@ func newUninstallCmd(opts *lefthook.Options) *cobra.Command { Use: "uninstall", Short: "Revert install command", ValidArgsFunction: cobra.NoFileCompletions, + Args: cobra.NoArgs, RunE: func(cmd *cobra.Command, _args []string) error { return lefthook.Uninstall(opts, &args) }, diff --git a/cmd/version.go b/cmd/version.go index 858498f0..b6c1a8e7 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -15,6 +15,7 @@ func newVersionCmd(_opts *lefthook.Options) *cobra.Command { Use: "version", Short: "Show lefthook version", ValidArgsFunction: cobra.NoFileCompletions, + Args: cobra.NoArgs, Run: func(cmd *cobra.Command, args []string) { log.Println(version.Version(verbose)) },