forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
86 lines (67 loc) · 2.71 KB
/
cli.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package cli
import (
"fmt"
"os"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/clientcmd"
kubecmd "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/openshift/origin/pkg/cmd/cli/cmd"
)
const longDesc = `
OpenShift Client
The OpenShift client exposes commands for managing your applications, as well as lower level
tools to interact with each component of your system.
At the present time, the CLI wraps many of the upstream Kubernetes commands and works generically
on all resources. Some commands you can try:
$ %[1]s get pods
Note: This is an alpha release of OpenShift and will change significantly. See
https://github.com/openshift/origin for the latest information on OpenShift.
`
func NewCommandCLI(name string) *cobra.Command {
// Main command
cmds := &cobra.Command{
Use: name,
Aliases: []string{"kubectl"},
Short: "Client tools for OpenShift",
Long: fmt.Sprintf(longDesc, name),
Run: func(c *cobra.Command, args []string) {
c.Help()
},
}
// Override global default to https and port 8443
clientcmd.DefaultCluster.Server = "https://localhost:8443"
// TODO: there should be two client configs, one for OpenShift, and one for Kubernetes
clientConfig := defaultClientConfig(cmds.PersistentFlags())
f := cmd.NewFactory(clientConfig)
f.BindFlags(cmds.PersistentFlags())
out := os.Stdout
// Kubernetes CRUD commands
cmds.AddCommand(f.NewCmdGet(out))
cmds.AddCommand(f.NewCmdDescribe(out))
cmds.AddCommand(f.NewCmdCreate(out))
cmds.AddCommand(f.NewCmdUpdate(out))
cmds.AddCommand(f.NewCmdDelete(out))
cmds.AddCommand(kubecmd.NewCmdNamespace(out))
// Kubernetes support commands
cmds.AddCommand(f.NewCmdLog(out))
cmds.AddCommand(f.NewCmdProxy(out))
// Origin commands
cmds.AddCommand(cmd.NewCmdApply(f, out))
cmds.AddCommand(cmd.NewCmdProcess(f, out))
// Origin build commands
cmds.AddCommand(cmd.NewCmdBuildLogs(f, out))
cmds.AddCommand(cmd.NewCmdStartBuild(f, out))
cmds.AddCommand(cmd.NewCmdCancelBuild(f, out))
return cmds
}
// Copy of kubectl/cmd/DefaultClientConfig, using NewNonInteractiveDeferredLoadingClientConfig
func defaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig {
loadingRules := clientcmd.NewClientConfigLoadingRules()
loadingRules.EnvVarPath = os.Getenv(clientcmd.RecommendedConfigPathEnvVar)
flags.StringVar(&loadingRules.CommandLinePath, "kubeconfig", "", "Path to the kubeconfig file to use for CLI requests.")
overrides := &clientcmd.ConfigOverrides{}
clientcmd.BindOverrideFlags(overrides, flags, clientcmd.RecommendedConfigOverrideFlags(""))
clientConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides)
return clientConfig
}