add completion cli command.

This commit is contained in:
Billy Shambrook 2016-11-05 00:27:06 +00:00
parent 8e979ca434
commit ea689f8ca9
3 changed files with 128 additions and 1 deletions

89
cmd/kops/completion.go Normal file
View File

@ -0,0 +1,89 @@
/*
Copyright 2016 The Kubernetes Authors.
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 main
import (
"fmt"
"io"
"os"
"github.com/spf13/cobra"
)
const boilerPlate = `
# Copyright 2016 The Kubernetes Authors.
#
# 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.
`
type CompletionCmd struct {
cobraCommand *cobra.Command
Shell string
}
var completionCmd = CompletionCmd{
cobraCommand: &cobra.Command{
Use: "completion",
Short: "Outputs kops shell completion for the given shell (bash)",
},
}
func init() {
cmd := completionCmd.cobraCommand
rootCommand.cobraCommand.AddCommand(cmd)
cmd.Run = func(cmd *cobra.Command, args []string) {
err := completionCmd.Run(os.Stdout)
if err != nil {
exitWithError(err)
}
}
cmd.Flags().StringVar(&completionCmd.Shell, "shell", "", "target shell (bash).")
}
func (c *CompletionCmd) Run(w io.Writer) error {
if c.Shell == "" {
return fmt.Errorf("--shell is required")
}
if c.Shell != "bash" {
return fmt.Errorf("only bash shell is supported for kops completion")
}
_, err := w.Write([]byte(boilerPlate))
if err != nil {
return err
}
err = rootCommand.cobraCommand.GenBashCompletion(w)
if err != nil {
return err
}
return nil
}

View File

@ -24,12 +24,12 @@ It allows you to create, destroy, upgrade and maintain clusters.
```
### SEE ALSO
* [kops completion](kops_completion.md) - Outputs kops shell completion for the given shell (bash)
* [kops create](kops_create.md) - Create a resource by filename or stdin
* [kops delete](kops_delete.md) - delete clusters
* [kops describe](kops_describe.md) - describe objects
* [kops edit](kops_edit.md) - edit items
* [kops export](kops_export.md) - export clusters/kubecfg
* [kops genhelpdocs](kops_genhelpdocs.md) - Generate CLI help docs
* [kops get](kops_get.md) - list or get objects
* [kops import](kops_import.md) - import clusters
* [kops rolling-update](kops_rolling-update.md) - rolling update clusters

View File

@ -0,0 +1,38 @@
## kops completion
Outputs kops shell completion for the given shell (bash)
### Synopsis
Outputs kops shell completion for the given shell (bash)
```
kops completion
```
### Options
```
--shell string target shell (bash).
```
### Options inherited from parent commands
```
--alsologtostderr log to standard error as well as files
--config string config file (default is $HOME/.kops.yaml)
--log_backtrace_at traceLocation when logging hits line file:N, emit a stack trace (default :0)
--log_dir string If non-empty, write log files in this directory
--logtostderr log to standard error instead of files (default false)
--name string Name of cluster
--state string Location of state storage
--stderrthreshold severity logs at or above this threshold go to stderr (default 2)
-v, --v Level log level for V logs
--vmodule moduleSpec comma-separated list of pattern=N settings for file-filtered logging
```
### SEE ALSO
* [kops](kops.md) - kops is kubernetes ops
###### Auto generated by spf13/cobra on 5-Nov-2016