Skip to content

Commit

Permalink
Merge pull request #188 from mig4/187-adjust-help-when-used-as-kubect…
Browse files Browse the repository at this point in the history
…l-plugin

feat: adjust help when used as kubectl plugin
  • Loading branch information
garethr committed Apr 14, 2020
2 parents e3fe5a0 + e473b38 commit ce26286
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 8 additions & 0 deletions acceptance.bats
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,11 @@
[ "$status" -eq 0 ]
[ "$output" = "PASS - fixtures/valid.yaml contains a valid ReplicationController" ]
}

@test "Adjusts help string when invoked as a kubectl plugin" {
ln -s kubeval bin/kubectl-kubeval

run bin/kubectl-kubeval --help
[ "$status" -eq 0 ]
[[ ${lines[2]} == " kubectl kubeval <file>"* ]]
}
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ var (

// RootCmd represents the the command to run when kubeval is run
var RootCmd = &cobra.Command{
Use: "kubeval <file> [file...]",
Short: "Validate a Kubernetes YAML file against the relevant schema",
Long: `Validate a Kubernetes YAML file against the relevant schema`,
Version: fmt.Sprintf("Version: %s\nCommit: %s\nDate: %s\n", version, commit, date),
Expand Down Expand Up @@ -196,6 +195,11 @@ func Execute() {
}

func init() {
rootCmdName := filepath.Base(os.Args[0])
if strings.HasPrefix(rootCmdName, "kubectl-") {
rootCmdName = strings.Replace(rootCmdName, "-", " ", 1)
}
RootCmd.Use = fmt.Sprintf("%s <file> [file...]", rootCmdName)
kubeval.AddKubevalFlags(RootCmd, config)
RootCmd.Flags().BoolVarP(&forceColor, "force-color", "", false, "Force colored output even if stdout is not a TTY")
RootCmd.SetVersionTemplate(`{{.Version}}`)
Expand Down

0 comments on commit ce26286

Please sign in to comment.