forked from openshift/origin
/
openshift.go
139 lines (118 loc) · 4.75 KB
/
openshift.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package openshift
import (
"fmt"
"os"
"runtime"
"strings"
"github.com/spf13/cobra"
"github.com/openshift/origin/pkg/cmd/admin"
"github.com/openshift/origin/pkg/cmd/cli"
"github.com/openshift/origin/pkg/cmd/experimental/buildchain"
"github.com/openshift/origin/pkg/cmd/experimental/config"
"github.com/openshift/origin/pkg/cmd/experimental/generate"
"github.com/openshift/origin/pkg/cmd/experimental/policy"
"github.com/openshift/origin/pkg/cmd/experimental/project"
exregistry "github.com/openshift/origin/pkg/cmd/experimental/registry"
exrouter "github.com/openshift/origin/pkg/cmd/experimental/router"
"github.com/openshift/origin/pkg/cmd/experimental/tokens"
"github.com/openshift/origin/pkg/cmd/flagtypes"
"github.com/openshift/origin/pkg/cmd/infra/builder"
"github.com/openshift/origin/pkg/cmd/infra/deployer"
"github.com/openshift/origin/pkg/cmd/infra/router"
"github.com/openshift/origin/pkg/cmd/server/start"
"github.com/openshift/origin/pkg/cmd/templates"
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
"github.com/openshift/origin/pkg/version"
)
const longDescription = `
OpenShift Application Platform
OpenShift helps you build, deploy, and manage your applications. To start an all-in-one server, run:
$ openshift start &
OpenShift is built around Docker and the Kubernetes cluster container manager. You must have
Docker installed on this machine to start your server.
Note: This is a beta release of OpenShift and may change significantly. See
https://github.com/openshift/origin for the latest information on OpenShift.
`
// CommandFor returns the appropriate command for this base name,
// or the global OpenShift command
func CommandFor(basename string) *cobra.Command {
var cmd *cobra.Command
// Make case-insensitive and strip executable suffix if present
if runtime.GOOS == "windows" {
basename = strings.ToLower(basename)
basename = strings.TrimSuffix(basename, ".exe")
}
switch basename {
case "openshift-router":
cmd = router.NewCommandTemplateRouter(basename)
case "openshift-deploy":
cmd = deployer.NewCommandDeployer(basename)
case "openshift-sti-build":
cmd = builder.NewCommandSTIBuilder(basename)
case "openshift-docker-build":
cmd = builder.NewCommandDockerBuilder(basename)
case "osc":
cmd = cli.NewCommandCLI(basename, basename)
case "osadm":
cmd = admin.NewCommandAdmin(basename, basename, os.Stdout)
default:
cmd = NewCommandOpenShift()
}
templates.UseMainTemplates(cmd)
flagtypes.GLog(cmd.PersistentFlags())
return cmd
}
// NewCommandOpenShift creates the standard OpenShift command
func NewCommandOpenShift() *cobra.Command {
root := &cobra.Command{
Use: "openshift",
Short: "OpenShift helps you build, deploy, and manage your cloud applications",
Long: longDescription,
Run: func(c *cobra.Command, args []string) {
c.SetOutput(os.Stdout)
c.Help()
},
}
startAllInOne, _ := start.NewCommandStartAllInOne()
root.AddCommand(startAllInOne)
root.AddCommand(admin.NewCommandAdmin("admin", "openshift admin", os.Stdout))
root.AddCommand(cli.NewCommandCLI("cli", "openshift cli"))
root.AddCommand(cli.NewCmdKubectl("kube"))
root.AddCommand(newExperimentalCommand("openshift", "ex"))
root.AddCommand(version.NewVersionCommand("openshift"))
// infra commands are those that are bundled with the binary but not displayed to end users
// directly
infra := &cobra.Command{
Use: "infra", // Because this command exposes no description, it will not be shown in help
}
infra.AddCommand(
router.NewCommandTemplateRouter("router"),
deployer.NewCommandDeployer("deploy"),
builder.NewCommandSTIBuilder("sti-build"),
builder.NewCommandDockerBuilder("docker-build"),
)
root.AddCommand(infra)
return root
}
func newExperimentalCommand(parentName, name string) *cobra.Command {
experimental := &cobra.Command{
Use: name,
Short: "Experimental commands under active development",
Long: "The commands grouped here are under development and may change without notice.",
Run: func(c *cobra.Command, args []string) {
c.SetOutput(os.Stdout)
c.Help()
},
}
f := clientcmd.New(experimental.PersistentFlags())
subName := fmt.Sprintf("%s %s", parentName, name)
experimental.AddCommand(project.NewCmdNewProject(f, subName, "new-project"))
experimental.AddCommand(config.NewCmdConfig(subName, "config"))
experimental.AddCommand(tokens.NewCmdTokens(f, subName, "tokens"))
experimental.AddCommand(policy.NewCommandPolicy(f, subName, "policy"))
experimental.AddCommand(generate.NewCmdGenerate(f, subName, "generate", os.Stdout))
experimental.AddCommand(exrouter.NewCmdRouter(f, subName, "router", os.Stdout))
experimental.AddCommand(exregistry.NewCmdRegistry(f, subName, "registry", os.Stdout))
experimental.AddCommand(buildchain.NewCmdBuildChain(f, subName, "build-chain"))
return experimental
}