Skip to content

Commit

Permalink
fix(cli) better error messages on invalid commands
Browse files Browse the repository at this point in the history
  • Loading branch information
peterldowns committed Dec 29, 2023
1 parent 6fd5535 commit ce353ff
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions cmd/localias/root/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package root

import (
"fmt"

"github.com/spf13/cobra"

"github.com/peterldowns/localias/cmd/localias/debug"
Expand Down Expand Up @@ -34,6 +36,12 @@ localias stop
# Run the proxy server in the foreground
localias run
`),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
return fmt.Errorf(`invalid command: "%s"`, args[0])
}
return cmd.Help()
},
}

func init() { //nolint:gochecknoinits
Expand All @@ -46,6 +54,4 @@ func init() { //nolint:gochecknoinits
shared.Flags.Configfile = Command.PersistentFlags().StringP("configfile", "c", "", "path to the configuration file to edit")

Command.AddCommand(debug.Command)

Command.AddCommand()
}

0 comments on commit ce353ff

Please sign in to comment.