From 45c92cefec68ba5311da5f266abb66e8496f10d4 Mon Sep 17 00:00:00 2001 From: Marvin Steadfast Date: Mon, 14 Jun 2021 20:18:56 +0200 Subject: [PATCH] command must be a flag now --- cmd/cmds/root.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/cmds/root.go b/cmd/cmds/root.go index cf199b0..2c96fba 100644 --- a/cmd/cmds/root.go +++ b/cmd/cmds/root.go @@ -3,7 +3,6 @@ package cmds import ( "fmt" - "os" "time" "github.com/rs/zerolog/log" @@ -17,6 +16,7 @@ const ( ) var ( + command string timeout time.Duration retry time.Duration ) @@ -28,10 +28,9 @@ var ( ) var rootCmd = &cobra.Command{ - Use: "don [command]", - Args: cobra.ExactArgs(1), + Use: "don [command]", Run: func(cmd *cobra.Command, args []string) { - if err := don.Check(don.Cmd(os.Args[1]), timeout, retry); err != nil { + if err := don.Check(don.Cmd(command), timeout, retry); err != nil { log.Fatal().Err(err).Msg("received error") } @@ -50,6 +49,12 @@ var versionCmd = &cobra.Command{ func init() { rootCmd.AddCommand(versionCmd) + rootCmd.Flags().StringVarP(&command, "command", "c", "", "command to run (required)") + + if err := rootCmd.MarkFlagRequired("command"); err != nil { + log.Fatal().Err(err).Msg("needs command flag") + } + rootCmd.Flags().DurationVarP(&timeout, "timeout", "t", defaultTimeout, "timeout") rootCmd.Flags().DurationVarP(&retry, "retry", "r", defaultRetry, "retry") }