command must be a flag now
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
Marvin Steadfast 2021-06-14 20:18:56 +02:00
parent fffbad8a44
commit 45c92cefec

View File

@ -3,7 +3,6 @@ package cmds
import ( import (
"fmt" "fmt"
"os"
"time" "time"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
@ -17,6 +16,7 @@ const (
) )
var ( var (
command string
timeout time.Duration timeout time.Duration
retry time.Duration retry time.Duration
) )
@ -29,9 +29,8 @@ var (
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
Use: "don [command]", Use: "don [command]",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) { 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") log.Fatal().Err(err).Msg("received error")
} }
@ -50,6 +49,12 @@ var versionCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(versionCmd) 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(&timeout, "timeout", "t", defaultTimeout, "timeout")
rootCmd.Flags().DurationVarP(&retry, "retry", "r", defaultRetry, "retry") rootCmd.Flags().DurationVarP(&retry, "retry", "r", defaultRetry, "retry")
} }