-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Copy pathcommands.go
67 lines (58 loc) · 2 KB
/
commands.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
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
// Package commands holds the CLI glue mapping textual commands/args to method calls.
package commands
import (
"flag"
"io"
"os"
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/api/konfig"
"sigs.k8s.io/kustomize/api/provider"
"sigs.k8s.io/kustomize/cmd/config/completion"
"sigs.k8s.io/kustomize/cmd/config/configcobra"
"sigs.k8s.io/kustomize/kustomize/v5/commands/build"
"sigs.k8s.io/kustomize/kustomize/v5/commands/create"
"sigs.k8s.io/kustomize/kustomize/v5/commands/edit"
"sigs.k8s.io/kustomize/kustomize/v5/commands/localize"
"sigs.k8s.io/kustomize/kustomize/v5/commands/openapi"
"sigs.k8s.io/kustomize/kustomize/v5/commands/version"
"sigs.k8s.io/kustomize/kyaml/filesys"
)
func makeBuildCommand(fSys filesys.FileSystem, w io.Writer) *cobra.Command {
cmd := build.NewCmdBuild(
fSys, build.MakeHelp(konfig.ProgramName, "build"), w)
// Add build flags that don't appear in kubectl.
build.AddFunctionAlphaEnablementFlags(cmd.Flags())
return cmd
}
// NewDefaultCommand returns the default (aka root) command for kustomize command.
func NewDefaultCommand() *cobra.Command {
fSys := filesys.MakeFsOnDisk()
stdOut := os.Stdout
c := &cobra.Command{
Use: konfig.ProgramName,
Short: "Manages declarative configuration of Kubernetes",
Long: `
Manages declarative configuration of Kubernetes.
See https://sigs.k8s.io/kustomize
`,
}
pvd := provider.NewDefaultDepProvider()
c.AddCommand(
completion.NewCommand(),
makeBuildCommand(fSys, stdOut),
edit.NewCmdEdit(
fSys, pvd.GetFieldValidator(), pvd.GetResourceFactory(), stdOut),
create.NewCmdCreate(fSys, pvd.GetResourceFactory()),
version.NewCmdVersion(stdOut),
openapi.NewCmdOpenAPI(stdOut),
localize.NewCmdLocalize(fSys),
)
configcobra.AddCommands(c, konfig.ProgramName)
c.PersistentFlags().AddGoFlagSet(flag.CommandLine)
// Workaround for this issue:
// https://github.com/kubernetes/kubernetes/issues/17162
flag.CommandLine.Parse([]string{})
return c
}