2014-10-06 01:24:19 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2014-10-06 01:24:19 +00:00
|
|
|
|
|
|
|
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 (
|
2016-08-20 00:03:39 +00:00
|
|
|
"fmt"
|
2014-10-06 01:24:19 +00:00
|
|
|
"io"
|
|
|
|
|
2017-01-23 14:46:05 +00:00
|
|
|
"k8s.io/apiserver/pkg/util/flag"
|
2017-01-20 18:06:17 +00:00
|
|
|
"k8s.io/client-go/tools/clientcmd"
|
2017-02-07 14:41:48 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/cmd/auth"
|
2015-08-05 22:03:47 +00:00
|
|
|
cmdconfig "k8s.io/kubernetes/pkg/kubectl/cmd/config"
|
2016-01-20 21:35:01 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/cmd/rollout"
|
2016-05-11 00:24:05 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/cmd/set"
|
2016-08-20 00:03:39 +00:00
|
|
|
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
2015-08-05 22:03:47 +00:00
|
|
|
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
2016-12-14 07:18:11 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/i18n"
|
2014-11-17 18:29:45 +00:00
|
|
|
|
2016-08-20 00:03:39 +00:00
|
|
|
"github.com/golang/glog"
|
2014-10-06 01:24:19 +00:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2015-03-17 17:00:48 +00:00
|
|
|
const (
|
2017-02-16 03:47:00 +00:00
|
|
|
bashCompletionFunc = `# call kubectl get $1,
|
2016-04-04 19:04:00 +00:00
|
|
|
__kubectl_override_flag_list=(kubeconfig cluster user context namespace server)
|
|
|
|
__kubectl_override_flags()
|
2016-03-20 18:14:25 +00:00
|
|
|
{
|
2016-04-04 19:04:00 +00:00
|
|
|
local ${__kubectl_override_flag_list[*]} two_word_of of
|
2016-03-20 18:14:25 +00:00
|
|
|
for w in "${words[@]}"; do
|
2016-04-04 19:04:00 +00:00
|
|
|
if [ -n "${two_word_of}" ]; then
|
|
|
|
eval "${two_word_of}=\"--${two_word_of}=\${w}\""
|
|
|
|
two_word_of=
|
2016-03-20 18:14:25 +00:00
|
|
|
continue
|
|
|
|
fi
|
2016-04-04 19:04:00 +00:00
|
|
|
for of in "${__kubectl_override_flag_list[@]}"; do
|
|
|
|
case "${w}" in
|
|
|
|
--${of}=*)
|
2016-08-22 12:51:15 +00:00
|
|
|
eval "${of}=\"${w}\""
|
2016-04-04 19:04:00 +00:00
|
|
|
;;
|
|
|
|
--${of})
|
|
|
|
two_word_of="${of}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
if [ "${w}" == "--all-namespaces" ]; then
|
|
|
|
namespace="--all-namespaces"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
for of in "${__kubectl_override_flag_list[@]}"; do
|
|
|
|
if eval "test -n \"\$${of}\""; then
|
|
|
|
eval "echo \${${of}}"
|
|
|
|
fi
|
2016-03-20 18:14:25 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
__kubectl_get_namespaces()
|
|
|
|
{
|
2017-06-29 14:12:22 +00:00
|
|
|
__kubectl_parse_get "namespace"
|
2016-03-20 18:14:25 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 06:11:21 +00:00
|
|
|
__kubectl_config_get_contexts()
|
|
|
|
{
|
|
|
|
__kubectl_parse_config "contexts"
|
|
|
|
}
|
|
|
|
|
|
|
|
__kubectl_config_get_clusters()
|
|
|
|
{
|
|
|
|
__kubectl_parse_config "clusters"
|
|
|
|
}
|
|
|
|
|
|
|
|
__kubectl_config_get_users()
|
|
|
|
{
|
|
|
|
__kubectl_parse_config "users"
|
|
|
|
}
|
|
|
|
|
|
|
|
# $1 has to be "contexts", "clusters" or "users"
|
2017-06-10 22:12:23 +00:00
|
|
|
__kubectl_parse_config()
|
2017-02-25 14:54:56 +00:00
|
|
|
{
|
|
|
|
local template kubectl_out
|
2017-04-09 06:11:21 +00:00
|
|
|
template="{{ range .$1 }}{{ .name }} {{ end }}"
|
2017-02-25 14:54:56 +00:00
|
|
|
if kubectl_out=$(kubectl config $(__kubectl_override_flags) -o template --template="${template}" view 2>/dev/null); then
|
|
|
|
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-03-17 17:00:48 +00:00
|
|
|
__kubectl_parse_get()
|
|
|
|
{
|
2015-05-09 13:41:54 +00:00
|
|
|
local template
|
|
|
|
template="{{ range .items }}{{ .metadata.name }} {{ end }}"
|
|
|
|
local kubectl_out
|
2016-04-04 19:04:00 +00:00
|
|
|
if kubectl_out=$(kubectl get $(__kubectl_override_flags) -o template --template="${template}" "$1" 2>/dev/null); then
|
2015-05-09 13:41:54 +00:00
|
|
|
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
|
2015-03-17 17:00:48 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
__kubectl_get_resource()
|
|
|
|
{
|
|
|
|
if [[ ${#nouns[@]} -eq 0 ]]; then
|
|
|
|
return 1
|
|
|
|
fi
|
2015-05-04 18:50:17 +00:00
|
|
|
__kubectl_parse_get "${nouns[${#nouns[@]} -1]}"
|
2015-03-17 17:00:48 +00:00
|
|
|
}
|
|
|
|
|
2015-08-24 12:25:48 +00:00
|
|
|
__kubectl_get_resource_pod()
|
|
|
|
{
|
|
|
|
__kubectl_parse_get "pod"
|
|
|
|
}
|
|
|
|
|
2015-08-31 23:37:44 +00:00
|
|
|
__kubectl_get_resource_rc()
|
|
|
|
{
|
|
|
|
__kubectl_parse_get "rc"
|
|
|
|
}
|
|
|
|
|
2016-08-22 02:46:50 +00:00
|
|
|
__kubectl_get_resource_node()
|
|
|
|
{
|
|
|
|
__kubectl_parse_get "node"
|
|
|
|
}
|
|
|
|
|
2015-03-17 17:00:48 +00:00
|
|
|
# $1 is the name of the pod we want to get the list of containers inside
|
|
|
|
__kubectl_get_containers()
|
|
|
|
{
|
|
|
|
local template
|
2015-05-09 13:41:54 +00:00
|
|
|
template="{{ range .spec.containers }}{{ .name }} {{ end }}"
|
2015-05-04 18:50:17 +00:00
|
|
|
__debug "${FUNCNAME} nouns are ${nouns[*]}"
|
2015-03-17 17:00:48 +00:00
|
|
|
|
|
|
|
local len="${#nouns[@]}"
|
|
|
|
if [[ ${len} -ne 1 ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
local last=${nouns[${len} -1]}
|
|
|
|
local kubectl_out
|
2016-08-22 12:51:15 +00:00
|
|
|
if kubectl_out=$(kubectl get $(__kubectl_override_flags) -o template --template="${template}" pods "${last}" 2>/dev/null); then
|
2015-03-17 17:00:48 +00:00
|
|
|
COMPREPLY=( $( compgen -W "${kubectl_out[*]}" -- "$cur" ) )
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Require both a pod and a container to be specified
|
|
|
|
__kubectl_require_pod_and_container()
|
|
|
|
{
|
|
|
|
if [[ ${#nouns[@]} -eq 0 ]]; then
|
|
|
|
__kubectl_parse_get pods
|
|
|
|
return 0
|
|
|
|
fi;
|
|
|
|
__kubectl_get_containers
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
__custom_func() {
|
|
|
|
case ${last_command} in
|
2016-04-03 10:13:51 +00:00
|
|
|
kubectl_get | kubectl_describe | kubectl_delete | kubectl_label | kubectl_stop | kubectl_edit | kubectl_patch |\
|
2016-08-22 02:46:50 +00:00
|
|
|
kubectl_annotate | kubectl_expose | kubectl_scale | kubectl_autoscale | kubectl_taint | kubectl_rollout_*)
|
2015-08-24 12:25:48 +00:00
|
|
|
__kubectl_get_resource
|
|
|
|
return
|
|
|
|
;;
|
2016-08-22 02:46:50 +00:00
|
|
|
kubectl_logs | kubectl_attach)
|
2015-08-24 12:25:48 +00:00
|
|
|
__kubectl_require_pod_and_container
|
|
|
|
return
|
|
|
|
;;
|
2016-08-22 02:46:50 +00:00
|
|
|
kubectl_exec | kubectl_port-forward | kubectl_top_pod)
|
2015-08-24 12:25:48 +00:00
|
|
|
__kubectl_get_resource_pod
|
2015-03-17 17:00:48 +00:00
|
|
|
return
|
|
|
|
;;
|
2015-08-31 23:37:44 +00:00
|
|
|
kubectl_rolling-update)
|
|
|
|
__kubectl_get_resource_rc
|
|
|
|
return
|
|
|
|
;;
|
2016-08-22 02:46:50 +00:00
|
|
|
kubectl_cordon | kubectl_uncordon | kubectl_drain | kubectl_top_node)
|
|
|
|
__kubectl_get_resource_node
|
|
|
|
return
|
|
|
|
;;
|
2017-03-01 15:48:08 +00:00
|
|
|
kubectl_config_use-context)
|
2017-04-09 06:11:21 +00:00
|
|
|
__kubectl_config_get_contexts
|
2017-03-01 15:48:08 +00:00
|
|
|
return
|
|
|
|
;;
|
2015-03-17 17:00:48 +00:00
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
2015-07-07 03:14:28 +00:00
|
|
|
`
|
2016-02-18 22:31:08 +00:00
|
|
|
|
|
|
|
// If you add a resource to this list, please also take a look at pkg/kubectl/kubectl.go
|
|
|
|
// and add a short forms entry in expandResourceShortcut() when appropriate.
|
2016-08-30 17:49:49 +00:00
|
|
|
// TODO: This should be populated using the discovery information from apiserver.
|
2017-02-16 03:47:00 +00:00
|
|
|
validResources = `Valid resource types include:
|
2016-10-07 22:24:42 +00:00
|
|
|
|
2016-11-29 06:45:10 +00:00
|
|
|
* all
|
2017-01-20 21:14:51 +00:00
|
|
|
* certificatesigningrequests (aka 'csr')
|
2016-11-23 09:49:43 +00:00
|
|
|
* clusterrolebindings
|
|
|
|
* clusterroles
|
2017-03-17 15:58:17 +00:00
|
|
|
* clusters (valid only for federation apiservers)
|
2016-10-07 22:24:42 +00:00
|
|
|
* componentstatuses (aka 'cs')
|
|
|
|
* configmaps (aka 'cm')
|
2017-05-31 20:18:26 +00:00
|
|
|
* controllerrevisions
|
2017-03-17 15:58:17 +00:00
|
|
|
* cronjobs
|
2016-10-07 22:24:42 +00:00
|
|
|
* daemonsets (aka 'ds')
|
|
|
|
* deployments (aka 'deploy')
|
|
|
|
* endpoints (aka 'ep')
|
2016-10-30 20:47:25 +00:00
|
|
|
* events (aka 'ev')
|
2016-10-07 22:24:42 +00:00
|
|
|
* horizontalpodautoscalers (aka 'hpa')
|
2016-10-30 20:47:25 +00:00
|
|
|
* ingresses (aka 'ing')
|
2016-10-07 22:24:42 +00:00
|
|
|
* jobs
|
|
|
|
* limitranges (aka 'limits')
|
|
|
|
* namespaces (aka 'ns')
|
2017-02-28 10:45:13 +00:00
|
|
|
* networkpolicies (aka 'netpol')
|
2016-10-30 20:47:25 +00:00
|
|
|
* nodes (aka 'no')
|
2016-10-07 22:24:42 +00:00
|
|
|
* persistentvolumeclaims (aka 'pvc')
|
2016-10-30 20:47:25 +00:00
|
|
|
* persistentvolumes (aka 'pv')
|
2016-12-22 22:37:08 +00:00
|
|
|
* poddisruptionbudgets (aka 'pdb')
|
2017-04-21 02:11:01 +00:00
|
|
|
* podpreset
|
2017-03-17 15:58:17 +00:00
|
|
|
* pods (aka 'po')
|
2016-10-30 20:47:25 +00:00
|
|
|
* podsecuritypolicies (aka 'psp')
|
|
|
|
* podtemplates
|
2016-10-07 22:24:42 +00:00
|
|
|
* replicasets (aka 'rs')
|
|
|
|
* replicationcontrollers (aka 'rc')
|
2016-10-30 20:47:25 +00:00
|
|
|
* resourcequotas (aka 'quota')
|
2016-11-23 09:49:43 +00:00
|
|
|
* rolebindings
|
|
|
|
* roles
|
2016-10-07 22:24:42 +00:00
|
|
|
* secrets
|
|
|
|
* serviceaccounts (aka 'sa')
|
|
|
|
* services (aka 'svc')
|
2016-11-17 21:53:23 +00:00
|
|
|
* statefulsets
|
2016-10-30 20:47:25 +00:00
|
|
|
* storageclasses
|
|
|
|
* thirdpartyresources
|
2016-10-07 22:24:42 +00:00
|
|
|
`
|
2015-03-17 17:00:48 +00:00
|
|
|
)
|
|
|
|
|
2017-04-09 06:11:21 +00:00
|
|
|
var (
|
|
|
|
bash_completion_flags = map[string]string{
|
|
|
|
"namespace": "__kubectl_get_namespaces",
|
|
|
|
"context": "__kubectl_config_get_contexts",
|
|
|
|
"cluster": "__kubectl_config_get_clusters",
|
|
|
|
"user": "__kubectl_config_get_users",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2014-12-28 05:27:52 +00:00
|
|
|
// NewKubectlCommand creates the `kubectl` command and its nested children.
|
2016-10-13 00:18:39 +00:00
|
|
|
func NewKubectlCommand(f cmdutil.Factory, in io.Reader, out, err io.Writer) *cobra.Command {
|
2014-10-06 01:24:19 +00:00
|
|
|
// Parent command to which all subcommands are added.
|
|
|
|
cmds := &cobra.Command{
|
|
|
|
Use: "kubectl",
|
2017-01-25 01:00:32 +00:00
|
|
|
Short: i18n.T("kubectl controls the Kubernetes cluster manager"),
|
2016-10-07 22:24:42 +00:00
|
|
|
Long: templates.LongDesc(`
|
|
|
|
kubectl controls the Kubernetes cluster manager.
|
2014-10-06 01:24:19 +00:00
|
|
|
|
2016-10-07 22:24:42 +00:00
|
|
|
Find more information at https://github.com/kubernetes/kubernetes.`),
|
2014-10-06 01:24:19 +00:00
|
|
|
Run: runHelp,
|
2017-02-16 03:47:00 +00:00
|
|
|
BashCompletionFunction: bashCompletionFunc,
|
2014-10-06 01:24:19 +00:00
|
|
|
}
|
|
|
|
|
2014-12-28 05:27:52 +00:00
|
|
|
f.BindFlags(cmds.PersistentFlags())
|
2016-02-19 22:40:14 +00:00
|
|
|
f.BindExternalFlags(cmds.PersistentFlags())
|
2014-10-06 01:24:19 +00:00
|
|
|
|
2016-12-14 07:18:11 +00:00
|
|
|
// Sending in 'nil' for the getLanguageFn() results in using
|
|
|
|
// the LANG environment variable.
|
|
|
|
//
|
|
|
|
// TODO: Consider adding a flag or file preference for setting
|
|
|
|
// the language, instead of just loading from the LANG env. variable.
|
|
|
|
i18n.LoadTranslations("kubectl", nil)
|
|
|
|
|
2015-05-16 16:44:42 +00:00
|
|
|
// From this point and forward we get warnings on flags that contain "_" separators
|
2016-03-11 05:33:16 +00:00
|
|
|
cmds.SetGlobalNormalizationFunc(flag.WarnWordSepNormalizeFunc)
|
2015-05-16 16:44:42 +00:00
|
|
|
|
2016-08-20 00:03:39 +00:00
|
|
|
groups := templates.CommandGroups{
|
|
|
|
{
|
|
|
|
Message: "Basic Commands (Beginner):",
|
|
|
|
Commands: []*cobra.Command{
|
2016-09-21 23:41:07 +00:00
|
|
|
NewCmdCreate(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdExposeService(f, out),
|
|
|
|
NewCmdRun(f, in, out, err),
|
2017-05-19 17:40:21 +00:00
|
|
|
deprecatedAlias("run-container", NewCmdRun(f, in, out, err)),
|
2016-10-10 07:01:27 +00:00
|
|
|
set.NewCmdSet(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Message: "Basic Commands (Intermediate):",
|
|
|
|
Commands: []*cobra.Command{
|
|
|
|
NewCmdGet(f, out, err),
|
2016-08-23 01:40:57 +00:00
|
|
|
NewCmdExplain(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdEdit(f, out, err),
|
2016-11-22 03:22:24 +00:00
|
|
|
NewCmdDelete(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Message: "Deploy Commands:",
|
|
|
|
Commands: []*cobra.Command{
|
2016-10-20 14:41:46 +00:00
|
|
|
rollout.NewCmdRollout(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdRollingUpdate(f, out),
|
2017-05-19 17:40:21 +00:00
|
|
|
deprecatedAlias("rollingupdate", NewCmdRollingUpdate(f, out)),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdScale(f, out),
|
2017-05-19 17:40:21 +00:00
|
|
|
deprecatedAlias("resize", NewCmdScale(f, out)),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdAutoscale(f, out),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Message: "Cluster Management Commands:",
|
|
|
|
Commands: []*cobra.Command{
|
2016-10-18 17:45:16 +00:00
|
|
|
NewCmdCertificate(f, out),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdClusterInfo(f, out),
|
2017-05-19 17:40:21 +00:00
|
|
|
deprecatedAlias("clusterinfo", NewCmdClusterInfo(f, out)),
|
2016-10-20 14:41:46 +00:00
|
|
|
NewCmdTop(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdCordon(f, out),
|
|
|
|
NewCmdUncordon(f, out),
|
2016-10-20 16:43:48 +00:00
|
|
|
NewCmdDrain(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdTaint(f, out),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Message: "Troubleshooting and Debugging Commands:",
|
|
|
|
Commands: []*cobra.Command{
|
2016-08-23 03:11:05 +00:00
|
|
|
NewCmdDescribe(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdLogs(f, out),
|
|
|
|
NewCmdAttach(f, in, out, err),
|
2016-09-28 16:41:42 +00:00
|
|
|
NewCmdExec(f, in, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdPortForward(f, out, err),
|
|
|
|
NewCmdProxy(f, out),
|
2017-03-17 13:55:46 +00:00
|
|
|
NewCmdCp(f, out, err),
|
2017-02-07 14:41:48 +00:00
|
|
|
auth.NewCmdAuth(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Message: "Advanced Commands:",
|
|
|
|
Commands: []*cobra.Command{
|
2016-11-11 22:38:36 +00:00
|
|
|
NewCmdApply(f, out, err),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdPatch(f, out),
|
|
|
|
NewCmdReplace(f, out),
|
2017-05-19 17:40:21 +00:00
|
|
|
deprecatedAlias("update", NewCmdReplace(f, out)),
|
2016-08-20 00:03:39 +00:00
|
|
|
NewCmdConvert(f, out),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Message: "Settings Commands:",
|
|
|
|
Commands: []*cobra.Command{
|
|
|
|
NewCmdLabel(f, out),
|
|
|
|
NewCmdAnnotate(f, out),
|
2017-03-17 13:55:46 +00:00
|
|
|
NewCmdCompletion(out, ""),
|
2016-08-20 00:03:39 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
groups.Add(cmds)
|
2015-02-07 00:33:42 +00:00
|
|
|
|
2016-08-20 00:03:39 +00:00
|
|
|
filters := []string{
|
|
|
|
"options",
|
2017-05-19 17:45:49 +00:00
|
|
|
deprecated("kubectl", "delete", cmds, NewCmdStop(f, out)),
|
2016-08-20 00:03:39 +00:00
|
|
|
}
|
2017-05-19 23:37:17 +00:00
|
|
|
|
|
|
|
// Hide the "alpha" subcommand if there are no alpha commands in this build.
|
|
|
|
alpha := NewCmdAlpha(f, in, out, err)
|
|
|
|
if !alpha.HasSubCommands() {
|
|
|
|
filters = append(filters, alpha.Name())
|
|
|
|
}
|
|
|
|
|
2016-08-20 00:03:39 +00:00
|
|
|
templates.ActsAsRootCommand(cmds, filters, groups...)
|
2016-08-11 15:24:22 +00:00
|
|
|
|
2017-04-09 06:11:21 +00:00
|
|
|
for name, completion := range bash_completion_flags {
|
|
|
|
if cmds.Flag(name) != nil {
|
|
|
|
if cmds.Flag(name).Annotations == nil {
|
|
|
|
cmds.Flag(name).Annotations = map[string][]string{}
|
|
|
|
}
|
|
|
|
cmds.Flag(name).Annotations[cobra.BashCompCustom] = append(
|
|
|
|
cmds.Flag(name).Annotations[cobra.BashCompCustom],
|
|
|
|
completion,
|
|
|
|
)
|
2017-02-25 14:54:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 23:37:17 +00:00
|
|
|
cmds.AddCommand(alpha)
|
2016-10-20 14:41:46 +00:00
|
|
|
cmds.AddCommand(cmdconfig.NewCmdConfig(clientcmd.NewDefaultPathOptions(), out, err))
|
2017-04-25 21:55:01 +00:00
|
|
|
cmds.AddCommand(NewCmdPlugin(f, in, out, err))
|
2016-08-20 00:03:39 +00:00
|
|
|
cmds.AddCommand(NewCmdVersion(f, out))
|
|
|
|
cmds.AddCommand(NewCmdApiVersions(f, out))
|
2017-05-19 17:40:21 +00:00
|
|
|
cmds.AddCommand(deprecatedAlias("apiversions", NewCmdApiVersions(f, out)))
|
2017-05-25 17:36:42 +00:00
|
|
|
cmds.AddCommand(NewCmdOptions(out))
|
2016-08-20 00:03:39 +00:00
|
|
|
|
2014-12-28 05:27:52 +00:00
|
|
|
return cmds
|
2014-10-06 01:24:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func runHelp(cmd *cobra.Command, args []string) {
|
|
|
|
cmd.Help()
|
|
|
|
}
|
|
|
|
|
2015-03-27 23:24:59 +00:00
|
|
|
func printDeprecationWarning(command, alias string) {
|
|
|
|
glog.Warningf("%s is DEPRECATED and will be removed in a future version. Use %s instead.", alias, command)
|
|
|
|
}
|
2016-08-20 00:03:39 +00:00
|
|
|
|
2017-05-19 17:40:21 +00:00
|
|
|
// deprecatedAlias is intended to be used to create a "wrapper" command around
|
|
|
|
// an existing command. The wrapper works the same but prints a deprecation
|
|
|
|
// message before running. This command is identical functionality.
|
|
|
|
func deprecatedAlias(deprecatedVersion string, cmd *cobra.Command) *cobra.Command {
|
2017-05-18 22:34:04 +00:00
|
|
|
// Have to be careful here because Cobra automatically extracts the name
|
|
|
|
// of the command from the .Use field.
|
|
|
|
originalName := cmd.Name()
|
|
|
|
|
|
|
|
cmd.Use = deprecatedVersion
|
|
|
|
cmd.Deprecated = fmt.Sprintf("use %q instead", originalName)
|
2017-05-30 07:43:50 +00:00
|
|
|
cmd.Short = fmt.Sprintf("%s. This command is deprecated, use %q instead", cmd.Short, originalName)
|
2017-05-18 22:34:04 +00:00
|
|
|
cmd.Hidden = true
|
|
|
|
return cmd
|
|
|
|
}
|
|
|
|
|
2017-05-19 17:45:49 +00:00
|
|
|
// deprecated is similar to deprecatedAlias, but it is used for deprecations
|
2017-05-19 17:40:21 +00:00
|
|
|
// that are not simple aliases; this command is actually a different
|
|
|
|
// (deprecated) codepath.
|
2017-05-19 17:45:49 +00:00
|
|
|
func deprecated(baseName, to string, parent, cmd *cobra.Command) string {
|
|
|
|
cmd.Long = fmt.Sprintf("Deprecated: all functionality can be found in \"%s %s\"", baseName, to)
|
|
|
|
cmd.Short = fmt.Sprintf("Deprecated: use %s", to)
|
2016-08-20 00:03:39 +00:00
|
|
|
parent.AddCommand(cmd)
|
|
|
|
return cmd.Name()
|
|
|
|
}
|