diff --git a/README.md b/README.md index be5a5f8..8d73729 100644 --- a/README.md +++ b/README.md @@ -216,10 +216,10 @@ Edit the JSON file with your new settings and use the `apply` subcommand ``` $ vi settings.json -$ synkctl inverter apply -f settings.json --force` +$ synkctl inverter apply -f settings.json force` ``` -Note that the `--force` argument must be supplied to acknowledge that you are doing something potentially dangerous: There is no validation of the settings. +Note that the `force` argument must be supplied to acknowledge that you are doing something potentially dangerous: There is no validation of the settings. ## The **synkctl** REST Client A CLI can be useful but for more complex scenarios, it's better to have a program that monitors and adjust settings by making API calls. For example: diff --git a/cmd/inverter_apply.go b/cmd/inverter_apply.go index 8a56e31..81f806d 100644 --- a/cmd/inverter_apply.go +++ b/cmd/inverter_apply.go @@ -30,7 +30,7 @@ import ( ) func confirmApply() bool { - fmt.Println("You did not specify \"--force=true\". Do you really want to proceed?") + fmt.Println("You did not pass the argument \"force\". Do you really want to proceed?") fmt.Println("[yes/NO])") var resp string fmt.Scan(&resp) @@ -61,9 +61,9 @@ func applyInverterSettings(ctx context.Context, in *os.File) error { var inverterApplyCmd = &cobra.Command{ Use: "apply", Short: "Applies the inverter settings from a file or stdin", - Args: cobra.ExactArgs(0), + Args: cobra.MatchAll(cobra.MaximumNArgs(1), cobra.OnlyValidArgs), RunE: func(cmd *cobra.Command, args []string) error { - if !forceFlag { + if len(args) != 1 { if !confirmApply() { fmt.Println("aborting") os.Exit(1) @@ -80,13 +80,11 @@ var inverterApplyCmd = &cobra.Command{ } return applyInverterSettings(cmd.Context(), in) }, + ValidArgs: []string{"force"}, } -var forceFlag bool - func init() { inverterCmd.AddCommand(inverterApplyCmd) - inverterApplyCmd.Flags().BoolVar(&forceFlag, "force", false, "Acknowledge the risks") inverterApplyCmd.Flags().StringP("file", "f", "", "JSON file with inverter settings") viper.BindPFlag("file", inverterApplyCmd.Flags().Lookup("file")) }