Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: do not output shell completion copyright header on error #10558

Merged
merged 1 commit into from
Mar 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 14 additions & 16 deletions cilium/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@ func initConfig() {
}
}

const copyRightHeader = `
# Copyright 2017 Authors of Cilium
const copyRightHeader = `# Copyright 2017-2020 Authors of Cilium
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -163,21 +162,20 @@ func newCmdCompletion(out io.Writer) *cobra.Command {

func runCompletion(out io.Writer, cmd *cobra.Command, args []string) error {
if len(args) > 1 {
return fmt.Errorf("Too many arguments. Expected only the shell type.")
}
if _, err := out.Write([]byte(copyRightHeader)); err != nil {
return err
}
if len(args) == 0 {
return cmd.Parent().GenBashCompletion(out)
return fmt.Errorf("too many arguments; expected only the shell type: %s", args)
}

switch args[0] {
case "bash":
return cmd.Parent().GenBashCompletion(out)
case "zsh":
return cmd.Parent().GenZshCompletion(out)
if len(args) == 0 || args[0] == "bash" {
if _, err := out.Write([]byte(copyRightHeader)); err != nil {
return err
}
return cmd.Root().GenBashCompletion(out)
}

return fmt.Errorf("Unexpected shell: %s.", args[0])
if args[0] == "zsh" {
if _, err := out.Write([]byte(copyRightHeader)); err != nil {
return err
}
return cmd.Root().GenZshCompletion(out)
}
return fmt.Errorf("unsupported shell: %s", args[0])
}