Skip to content

Commit

Permalink
feat(clients/zbctl): add command to generate shell completion
Browse files Browse the repository at this point in the history
  • Loading branch information
menski committed Oct 15, 2018
1 parent 16632fc commit 4d0163d
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions clients/zbctl/cmd/completion.go
@@ -0,0 +1,51 @@
// Copyright © 2018 Camunda Services GmbH (info@camunda.com)
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cmd

import (
"fmt"
"github.com/zeebe-io/zeebe/clients/zbctl/utils"
"os"

"github.com/spf13/cobra"
)

var completionShellFlag string

// completionCmd represents the completion command
var completionCmd = &cobra.Command{
Use: "completion",
Short: "Generate shell completion for zbctl",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("completion called")
switch completionShellFlag {
case "bash":
rootCmd.GenBashCompletion(os.Stdout)
break
case "zsh":
rootCmd.GenZshCompletion(os.Stdout)
break
default:
fmt.Println("Unsupported shell for completion generation", completionShellFlag)
os.Exit(utils.ExitCodeConfigurationError)
}
},
}

func init() {
rootCmd.AddCommand(completionCmd)
completionCmd.Flags().StringVar(&completionShellFlag, "shell", "bash", "Shell to generate completion for")
}

0 comments on commit 4d0163d

Please sign in to comment.