refactor(helm): Make all functions returning cobra.Command public

This change enables developers to compose commands from helm, from kubectl and other tools into custom CLI for
their projects running on kubernetes.

Closes #5311

Signed-off-by: Dmitry Melanchenko <dmelanchenko@salesforce.com>
pull/5353/head
Dmitry Melanchenko 7 years ago
parent ead111dd4f
commit 8068a34c76
No known key found for this signature in database
GPG Key ID: AD6BCF223C5A1193

@ -42,7 +42,8 @@ var (
} }
) )
func newCompletionCmd(out io.Writer) *cobra.Command { // NewCompletionCmd returns cobra.Command to generate autocompletion scripts for bash or zsh
func NewCompletionCmd(out io.Writer) *cobra.Command {
shells := []string{} shells := []string{}
for s := range completionShells { for s := range completionShells {
shells = append(shells, s) shells = append(shells, s)

@ -63,7 +63,8 @@ type createCmd struct {
starter string starter string
} }
func newCreateCmd(out io.Writer) *cobra.Command { // NewCreateCmd returns cobra.Command to create a new chart with the given name
func NewCreateCmd(out io.Writer) *cobra.Command {
cc := &createCmd{out: out} cc := &createCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -46,7 +46,7 @@ func TestCreateCmd(t *testing.T) {
defer os.Chdir(pwd) defer os.Chdir(pwd)
// Run a create // Run a create
cmd := newCreateCmd(ioutil.Discard) cmd := NewCreateCmd(ioutil.Discard)
if err := cmd.RunE(cmd, []string{cname}); err != nil { if err := cmd.RunE(cmd, []string{cname}); err != nil {
t.Errorf("Failed to run create: %s", err) t.Errorf("Failed to run create: %s", err)
return return
@ -117,7 +117,7 @@ func TestCreateStarterCmd(t *testing.T) {
defer os.Chdir(pwd) defer os.Chdir(pwd)
// Run a create // Run a create
cmd := newCreateCmd(ioutil.Discard) cmd := NewCreateCmd(ioutil.Discard)
cmd.ParseFlags([]string{"--starter", "starterchart"}) cmd.ParseFlags([]string{"--starter", "starterchart"})
if err := cmd.RunE(cmd, []string{cname}); err != nil { if err := cmd.RunE(cmd, []string{cname}); err != nil {
t.Errorf("Failed to run create: %s", err) t.Errorf("Failed to run create: %s", err)

@ -46,7 +46,8 @@ type deleteCmd struct {
client helm.Interface client helm.Interface
} }
func newDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command { // NewDeleteCmd returns cobra.Command to delete a release from Kubernetes
func NewDeleteCmd(c helm.Interface, out io.Writer) *cobra.Command {
del := &deleteCmd{ del := &deleteCmd{
out: out, out: out,
client: c, client: c,

@ -76,6 +76,6 @@ func TestDelete(t *testing.T) {
}, },
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newDeleteCmd(c, out) return NewDeleteCmd(c, out)
}) })
} }

@ -87,7 +87,8 @@ This will produce an error if the chart cannot be loaded. It will emit a warning
if it cannot find a requirements.yaml. if it cannot find a requirements.yaml.
` `
func newDependencyCmd(out io.Writer) *cobra.Command { // NewDependencyCmd returns cobra.Command to manage chart dependencies
func NewDependencyCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "dependency update|build|list", Use: "dependency update|build|list",
Aliases: []string{"dep", "dependencies"}, Aliases: []string{"dep", "dependencies"},
@ -95,9 +96,9 @@ func newDependencyCmd(out io.Writer) *cobra.Command {
Long: dependencyDesc, Long: dependencyDesc,
} }
cmd.AddCommand(newDependencyListCmd(out)) cmd.AddCommand(NewDependencyListCmd(out))
cmd.AddCommand(newDependencyUpdateCmd(out)) cmd.AddCommand(NewDependencyUpdateCmd(out))
cmd.AddCommand(newDependencyBuildCmd(out)) cmd.AddCommand(NewDependencyBuildCmd(out))
return cmd return cmd
} }
@ -107,7 +108,8 @@ type dependencyListCmd struct {
chartpath string chartpath string
} }
func newDependencyListCmd(out io.Writer) *cobra.Command { // NewDependencyListCmd returns cobra.Command to list the dependencies for the given chart
func NewDependencyListCmd(out io.Writer) *cobra.Command {
dlc := &dependencyListCmd{out: out} dlc := &dependencyListCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -44,7 +44,8 @@ type dependencyBuildCmd struct {
helmhome helmpath.Home helmhome helmpath.Home
} }
func newDependencyBuildCmd(out io.Writer) *cobra.Command { // NewDependencyBuildCmd returns cobra.Command to rebuild the charts/ directory based on requirements.lock file
func NewDependencyBuildCmd(out io.Writer) *cobra.Command {
dbc := &dependencyBuildCmd{out: out} dbc := &dependencyBuildCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -53,6 +53,6 @@ func TestDependencyListCmd(t *testing.T) {
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newDependencyListCmd(out) return NewDependencyListCmd(out)
}) })
} }

@ -50,8 +50,8 @@ type dependencyUpdateCmd struct {
skipRefresh bool skipRefresh bool
} }
// newDependencyUpdateCmd creates a new dependency update command. // NewDependencyUpdateCmd returns cobra.Command to update charts/ based on content of requirements.yaml
func newDependencyUpdateCmd(out io.Writer) *cobra.Command { func NewDependencyUpdateCmd(out io.Writer) *cobra.Command {
duc := &dependencyUpdateCmd{out: out} duc := &dependencyUpdateCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -44,7 +44,8 @@ type docsCmd struct {
topCmd *cobra.Command topCmd *cobra.Command
} }
func newDocsCmd(out io.Writer) *cobra.Command { // NewDocsCmd returns cobra.Command to generate documentation as markdown or man pages
func NewDocsCmd(out io.Writer) *cobra.Command {
dc := &docsCmd{out: out} dc := &docsCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -68,7 +68,8 @@ type fetchCmd struct {
out io.Writer out io.Writer
} }
func newFetchCmd(out io.Writer) *cobra.Command { // NewFetchCmd returns cobra.Command to download a chart from a repository and (optionally) unpack it in local directory
func NewFetchCmd(out io.Writer) *cobra.Command {
fch := &fetchCmd{out: out} fch := &fetchCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -147,7 +147,7 @@ func TestFetchCmd(t *testing.T) {
os.Mkdir(outdir, 0755) os.Mkdir(outdir, 0755)
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
cmd := newFetchCmd(buf) cmd := NewFetchCmd(buf)
tt.flags = append(tt.flags, "-d", outdir) tt.flags = append(tt.flags, "-d", outdir)
cmd.ParseFlags(tt.flags) cmd.ParseFlags(tt.flags)
if err := cmd.RunE(cmd, []string{tt.chart}); err != nil { if err := cmd.RunE(cmd, []string{tt.chart}); err != nil {

@ -47,7 +47,8 @@ type getCmd struct {
version int32 version int32
} }
func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewGetCmd returns cobra.Command to download a names release
func NewGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
get := &getCmd{ get := &getCmd{
out: out, out: out,
client: client, client: client,
@ -74,10 +75,10 @@ func newGetCmd(client helm.Interface, out io.Writer) *cobra.Command {
settings.AddFlagsTLS(f) settings.AddFlagsTLS(f)
f.Int32Var(&get.version, "revision", 0, "get the named release with revision") f.Int32Var(&get.version, "revision", 0, "get the named release with revision")
cmd.AddCommand(newGetValuesCmd(nil, out)) cmd.AddCommand(NewGetValuesCmd(nil, out))
cmd.AddCommand(newGetManifestCmd(nil, out)) cmd.AddCommand(NewGetManifestCmd(nil, out))
cmd.AddCommand(newGetHooksCmd(nil, out)) cmd.AddCommand(NewGetHooksCmd(nil, out))
cmd.AddCommand(newGetNotesCmd(nil, out)) cmd.AddCommand(NewGetNotesCmd(nil, out))
// set defaults from environment // set defaults from environment
settings.InitTLS(f) settings.InitTLS(f)

@ -38,7 +38,8 @@ type getHooksCmd struct {
version int32 version int32
} }
func newGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewGetHooksCmd returns cobra.Command to download all hooks for a named release
func NewGetHooksCmd(client helm.Interface, out io.Writer) *cobra.Command {
ghc := &getHooksCmd{ ghc := &getHooksCmd{
out: out, out: out,
client: client, client: client,

@ -43,6 +43,6 @@ func TestGetHooks(t *testing.T) {
}, },
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newGetHooksCmd(c, out) return NewGetHooksCmd(c, out)
}) })
} }

@ -40,7 +40,8 @@ type getManifestCmd struct {
version int32 version int32
} }
func newGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewGetManifestCmd returns cobra.Command to download the manifest for a named release
func NewGetManifestCmd(client helm.Interface, out io.Writer) *cobra.Command {
get := &getManifestCmd{ get := &getManifestCmd{
out: out, out: out,
client: client, client: client,

@ -42,6 +42,6 @@ func TestGetManifest(t *testing.T) {
}, },
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newGetManifestCmd(c, out) return NewGetManifestCmd(c, out)
}) })
} }

@ -36,7 +36,8 @@ type getNotesCmd struct {
version int32 version int32
} }
func newGetNotesCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewGetNotesCmd returns cobra.Command to displays the notes of the named release
func NewGetNotesCmd(client helm.Interface, out io.Writer) *cobra.Command {
get := &getNotesCmd{ get := &getNotesCmd{
out: out, out: out,
client: client, client: client,

@ -46,7 +46,7 @@ func TestGetNotesCmd(t *testing.T) {
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newGetNotesCmd(c, out) return NewGetNotesCmd(c, out)
}) })
} }

@ -42,7 +42,7 @@ func TestGetCmd(t *testing.T) {
} }
cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command { cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newGetCmd(c, out) return NewGetCmd(c, out)
} }
runReleaseCases(t, tests, cmd) runReleaseCases(t, tests, cmd)
} }

@ -40,7 +40,8 @@ type getValuesCmd struct {
output string output string
} }
func newGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewGetValuesCmd returns cobra.Command to download the values file for a named release
func NewGetValuesCmd(client helm.Interface, out io.Writer) *cobra.Command {
get := &getValuesCmd{ get := &getValuesCmd{
out: out, out: out,
client: client, client: client,

@ -72,7 +72,7 @@ func TestGetValuesCmd(t *testing.T) {
}, },
} }
cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command { cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newGetValuesCmd(c, out) return NewGetValuesCmd(c, out)
} }
runReleaseCases(t, tests, cmd) runReleaseCases(t, tests, cmd)
} }

@ -77,7 +77,8 @@ Environment:
` `
func newRootCmd(args []string) *cobra.Command { // NewRootCmd returns cobra.Command for the root command of helm CLI
func NewRootCmd(args []string) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "helm", Use: "helm",
Short: "The Helm package manager for Kubernetes.", Short: "The Helm package manager for Kubernetes.",
@ -112,42 +113,42 @@ func newRootCmd(args []string) *cobra.Command {
cmd.AddCommand( cmd.AddCommand(
// chart commands // chart commands
newCreateCmd(out), NewCreateCmd(out),
newDependencyCmd(out), NewDependencyCmd(out),
newFetchCmd(out), NewFetchCmd(out),
newInspectCmd(out), NewInspectCmd(out),
newLintCmd(out), NewLintCmd(out),
newPackageCmd(out), NewPackageCmd(out),
newRepoCmd(out), NewRepoCmd(out),
newSearchCmd(out), NewSearchCmd(out),
newServeCmd(out), NewServeCmd(out),
newVerifyCmd(out), NewVerifyCmd(out),
// release commands // release commands
newDeleteCmd(nil, out), NewDeleteCmd(nil, out),
newGetCmd(nil, out), NewGetCmd(nil, out),
newHistoryCmd(nil, out), NewHistoryCmd(nil, out),
newInstallCmd(nil, out), NewInstallCmd(nil, out),
newListCmd(nil, out), NewListCmd(nil, out),
newRollbackCmd(nil, out), NewRollbackCmd(nil, out),
newStatusCmd(nil, out), NewStatusCmd(nil, out),
newUpgradeCmd(nil, out), NewUpgradeCmd(nil, out),
newReleaseTestCmd(nil, out), NewReleaseTestCmd(nil, out),
newResetCmd(nil, out), NewResetCmd(nil, out),
newVersionCmd(nil, out), NewVersionCmd(nil, out),
newCompletionCmd(out), NewCompletionCmd(out),
newHomeCmd(out), NewHomeCmd(out),
newInitCmd(out), NewInitCmd(out),
newPluginCmd(out), NewPluginCmd(out),
newTemplateCmd(out), NewTemplateCmd(out),
// Hidden documentation generator command: 'helm docs' // Hidden documentation generator command: 'helm docs'
newDocsCmd(out), NewDocsCmd(out),
// Deprecated // Deprecated
markDeprecated(newRepoUpdateCmd(out), "use 'helm repo update'\n"), markDeprecated(NewRepoUpdateCmd(out), "use 'helm repo update'\n"),
) )
flags.Parse(args) flags.Parse(args)
@ -167,7 +168,7 @@ func init() {
} }
func main() { func main() {
cmd := newRootCmd(os.Args[1:]) cmd := NewRootCmd(os.Args[1:])
if err := cmd.Execute(); err != nil { if err := cmd.Execute(); err != nil {
switch e := err.(type) { switch e := err.(type) {
case pluginError: case pluginError:

@ -211,7 +211,7 @@ func TestRootCmd(t *testing.T) {
os.Setenv(k, v) os.Setenv(k, v)
} }
cmd := newRootCmd(tt.args) cmd := NewRootCmd(tt.args)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tt.args) cmd.SetArgs(tt.args)
cmd.Run = func(*cobra.Command, []string) {} cmd.Run = func(*cobra.Command, []string) {}
@ -525,7 +525,7 @@ func TestTLSFlags(t *testing.T) {
defer os.Unsetenv(k) defer os.Unsetenv(k)
} }
cmd := newRootCmd(tt.args) cmd := NewRootCmd(tt.args)
cmd.SetOutput(ioutil.Discard) cmd.SetOutput(ioutil.Discard)
cmd.SetArgs(tt.args) cmd.SetArgs(tt.args)
cmd.Run = func(*cobra.Command, []string) {} cmd.Run = func(*cobra.Command, []string) {}

@ -66,7 +66,8 @@ type historyCmd struct {
outputFormat string outputFormat string
} }
func newHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command { // NewHistoryCmd returns cobra.Command to fetch release history
func NewHistoryCmd(c helm.Interface, w io.Writer) *cobra.Command {
his := &historyCmd{out: w, helmc: c} his := &historyCmd{out: w, helmc: c}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -80,6 +80,6 @@ func TestHistoryCmd(t *testing.T) {
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newHistoryCmd(c, out) return NewHistoryCmd(c, out)
}) })
} }

@ -28,7 +28,8 @@ This command displays the location of HELM_HOME. This is where
any helm configuration files live. any helm configuration files live.
` `
func newHomeCmd(out io.Writer) *cobra.Command { // NewHomeCmd returns cobra.Command to display the location of HELM_HOME
func NewHomeCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "home", Use: "home",
Short: "displays the location of HELM_HOME", Short: "displays the location of HELM_HOME",

@ -99,7 +99,8 @@ type initCmd struct {
wait bool wait bool
} }
func newInitCmd(out io.Writer) *cobra.Command { // NewInitCmd returns cobra.Command to initialize Helm on both client and server
func NewInitCmd(out io.Writer) *cobra.Command {
i := &initCmd{out: out} i := &initCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -75,7 +75,8 @@ const (
var readmeFileNames = []string{"readme.md", "readme.txt", "readme"} var readmeFileNames = []string{"readme.md", "readme.txt", "readme"}
func newInspectCmd(out io.Writer) *cobra.Command { // NewInspectCmd returns cobra.Command to inspect a chart
func NewInspectCmd(out io.Writer) *cobra.Command {
insp := &inspectCmd{ insp := &inspectCmd{
out: out, out: out,
output: all, output: all,

@ -129,7 +129,7 @@ func TestInspectPreReleaseChart(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
tt.flags = append(tt.flags, "--repo", srv.URL()) tt.flags = append(tt.flags, "--repo", srv.URL())
cmd := newInspectCmd(ioutil.Discard) cmd := NewInspectCmd(ioutil.Discard)
cmd.SetArgs(tt.args) cmd.SetArgs(tt.args)
cmd.ParseFlags(tt.flags) cmd.ParseFlags(tt.flags)
if err := cmd.RunE(cmd, tt.args); err != nil { if err := cmd.RunE(cmd, tt.args); err != nil {

@ -162,7 +162,8 @@ func (v *valueFiles) Set(value string) error {
return nil return nil
} }
func newInstallCmd(c helm.Interface, out io.Writer) *cobra.Command { // NewInstallCmd returns cobra.Command to install a chart archive
func NewInstallCmd(c helm.Interface, out io.Writer) *cobra.Command {
inst := &installCmd{ inst := &installCmd{
out: out, out: out,
client: c, client: c,

@ -194,7 +194,7 @@ func TestInstall(t *testing.T) {
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newInstallCmd(c, out) return NewInstallCmd(c, out)
}) })
} }

@ -54,7 +54,8 @@ type lintCmd struct {
out io.Writer out io.Writer
} }
func newLintCmd(out io.Writer) *cobra.Command { // NewLintCmd returns cobra.Command to examine a chart for possible issues
func NewLintCmd(out io.Writer) *cobra.Command {
l := &lintCmd{ l := &lintCmd{
paths: []string{"."}, paths: []string{"."},
out: out, out: out,

@ -96,7 +96,8 @@ type listRelease struct {
Namespace string Namespace string
} }
func newListCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewListCmd returns cobra.Command to list releases
func NewListCmd(client helm.Interface, out io.Writer) *cobra.Command {
list := &listCmd{ list := &listCmd{
out: out, out: out,
client: client, client: client,

@ -226,6 +226,6 @@ Releases: []
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newListCmd(c, out) return NewListCmd(c, out)
}) })
} }

@ -65,7 +65,8 @@ type packageCmd struct {
home helmpath.Home home helmpath.Home
} }
func newPackageCmd(out io.Writer) *cobra.Command { // NewPackageCmd returns cobra.Command to package a chart directory into a chart archive
func NewPackageCmd(out io.Writer) *cobra.Command {
pkg := &packageCmd{out: out} pkg := &packageCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -164,7 +164,7 @@ func TestPackage(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
c := newPackageCmd(buf) c := NewPackageCmd(buf)
// This is an unfortunate byproduct of the tmpdir // This is an unfortunate byproduct of the tmpdir
if v, ok := tt.flags["keyring"]; ok && len(v) > 0 { if v, ok := tt.flags["keyring"]; ok && len(v) > 0 {
@ -228,7 +228,7 @@ func TestSetAppVersion(t *testing.T) {
settings.Home = helmpath.Home(thome) settings.Home = helmpath.Home(thome)
c := newPackageCmd(&bytes.Buffer{}) c := NewPackageCmd(&bytes.Buffer{})
flags := map[string]string{ flags := map[string]string{
"destination": tmp, "destination": tmp,
"app-version": expectedAppVersion, "app-version": expectedAppVersion,

@ -30,17 +30,18 @@ const pluginHelp = `
Manage client-side Helm plugins. Manage client-side Helm plugins.
` `
func newPluginCmd(out io.Writer) *cobra.Command { // NewPluginCmd returns cobra.Command to add, list, or remove Helm plugins
func NewPluginCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "plugin", Use: "plugin",
Short: "add, list, or remove Helm plugins", Short: "add, list, or remove Helm plugins",
Long: pluginHelp, Long: pluginHelp,
} }
cmd.AddCommand( cmd.AddCommand(
newPluginInstallCmd(out), NewPluginInstallCmd(out),
newPluginListCmd(out), NewPluginListCmd(out),
newPluginRemoveCmd(out), NewPluginRemoveCmd(out),
newPluginUpdateCmd(out), NewPluginUpdateCmd(out),
) )
return cmd return cmd
} }

@ -40,7 +40,8 @@ Example usage:
$ helm plugin install https://github.com/technosophos/helm-template $ helm plugin install https://github.com/technosophos/helm-template
` `
func newPluginInstallCmd(out io.Writer) *cobra.Command { // NewPluginInstallCmd returns cobra.Command to install one or more Helm plugins
func NewPluginInstallCmd(out io.Writer) *cobra.Command {
pcmd := &pluginInstallCmd{out: out} pcmd := &pluginInstallCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "install [options] <path|url>...", Use: "install [options] <path|url>...",

@ -30,7 +30,8 @@ type pluginListCmd struct {
out io.Writer out io.Writer
} }
func newPluginListCmd(out io.Writer) *cobra.Command { // NewPluginListCmd returns cobra.Command to list installed Helm plugins
func NewPluginListCmd(out io.Writer) *cobra.Command {
pcmd := &pluginListCmd{out: out} pcmd := &pluginListCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "list", Use: "list",

@ -34,7 +34,8 @@ type pluginRemoveCmd struct {
out io.Writer out io.Writer
} }
func newPluginRemoveCmd(out io.Writer) *cobra.Command { // NewPluginRemoveCmd returns cobra.Command to remove one or more Helm plugins
func NewPluginRemoveCmd(out io.Writer) *cobra.Command {
pcmd := &pluginRemoveCmd{out: out} pcmd := &pluginRemoveCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "remove <plugin>...", Use: "remove <plugin>...",

@ -35,7 +35,8 @@ type pluginUpdateCmd struct {
out io.Writer out io.Writer
} }
func newPluginUpdateCmd(out io.Writer) *cobra.Command { // NewPluginUpdateCmd returns cobra.Command to update one or more Helm plugins
func NewPluginUpdateCmd(out io.Writer) *cobra.Command {
pcmd := &pluginUpdateCmd{out: out} pcmd := &pluginUpdateCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update <plugin>...", Use: "update <plugin>...",

@ -42,7 +42,8 @@ type releaseTestCmd struct {
parallel bool parallel bool
} }
func newReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command { // NewReleaseTestCmd returns cobra.Command to test a release
func NewReleaseTestCmd(c helm.Interface, out io.Writer) *cobra.Command {
rlsTest := &releaseTestCmd{ rlsTest := &releaseTestCmd{
out: out, out: out,
client: c, client: c,

@ -78,6 +78,6 @@ func TestReleaseTesting(t *testing.T) {
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newReleaseTestCmd(c, out) return NewReleaseTestCmd(c, out)
}) })
} }

@ -30,18 +30,19 @@ Example usage:
$ helm repo add [NAME] [REPO_URL] $ helm repo add [NAME] [REPO_URL]
` `
func newRepoCmd(out io.Writer) *cobra.Command { // NewRepoCmd returns cobra.Command to manage chart repositories
func NewRepoCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "repo [FLAGS] add|remove|list|index|update [ARGS]", Use: "repo [FLAGS] add|remove|list|index|update [ARGS]",
Short: "add, list, remove, update, and index chart repositories", Short: "add, list, remove, update, and index chart repositories",
Long: repoHelm, Long: repoHelm,
} }
cmd.AddCommand(newRepoAddCmd(out)) cmd.AddCommand(NewRepoAddCmd(out))
cmd.AddCommand(newRepoListCmd(out)) cmd.AddCommand(NewRepoListCmd(out))
cmd.AddCommand(newRepoRemoveCmd(out)) cmd.AddCommand(NewRepoRemoveCmd(out))
cmd.AddCommand(newRepoIndexCmd(out)) cmd.AddCommand(NewRepoIndexCmd(out))
cmd.AddCommand(newRepoUpdateCmd(out)) cmd.AddCommand(NewRepoUpdateCmd(out))
return cmd return cmd
} }

@ -44,7 +44,8 @@ type repoAddCmd struct {
out io.Writer out io.Writer
} }
func newRepoAddCmd(out io.Writer) *cobra.Command { // NewRepoAddCmd returns cobra.Command to add a chart repository
func NewRepoAddCmd(out io.Writer) *cobra.Command {
add := &repoAddCmd{out: out} add := &repoAddCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -57,7 +57,7 @@ func TestRepoAddCmd(t *testing.T) {
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newRepoAddCmd(out) return NewRepoAddCmd(out)
}) })
} }

@ -45,7 +45,8 @@ type repoIndexCmd struct {
merge string merge string
} }
func newRepoIndexCmd(out io.Writer) *cobra.Command { // NewRepoIndexCmd returns cobra.Command to generate an index file given a directory containing packaged charts
func NewRepoIndexCmd(out io.Writer) *cobra.Command {
index := &repoIndexCmd{out: out} index := &repoIndexCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -45,7 +45,7 @@ func TestRepoIndexCmd(t *testing.T) {
} }
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
c := newRepoIndexCmd(buf) c := NewRepoIndexCmd(buf)
if err := c.RunE(c, []string{dir}); err != nil { if err := c.RunE(c, []string{dir}); err != nil {
t.Error(err) t.Error(err)

@ -33,7 +33,8 @@ type repoListCmd struct {
home helmpath.Home home helmpath.Home
} }
func newRepoListCmd(out io.Writer) *cobra.Command { // NewRepoListCmd returns cobra.Command to list chart repositories
func NewRepoListCmd(out io.Writer) *cobra.Command {
list := &repoListCmd{out: out} list := &repoListCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -33,7 +33,8 @@ type repoRemoveCmd struct {
home helmpath.Home home helmpath.Home
} }
func newRepoRemoveCmd(out io.Writer) *cobra.Command { // NewRepoRemoveCmd returns cobra.Command to remove a chart repository
func NewRepoRemoveCmd(out io.Writer) *cobra.Command {
remove := &repoRemoveCmd{out: out} remove := &repoRemoveCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -82,7 +82,7 @@ func TestRepoRemove(t *testing.T) {
} }
func TestRepoRemove_NoArguments(t *testing.T) { func TestRepoRemove_NoArguments(t *testing.T) {
cmd := newRepoRemoveCmd(ioutil.Discard) cmd := NewRepoRemoveCmd(ioutil.Discard)
if err := cmd.RunE(cmd, []string{}); err == nil { if err := cmd.RunE(cmd, []string{}); err == nil {
t.Errorf("Expected an error since no repo names were provided") t.Errorf("Expected an error since no repo names were provided")
} }
@ -119,7 +119,7 @@ func TestRepoRemove_MultipleRepos(t *testing.T) {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
cmd := newRepoRemoveCmd(b) cmd := NewRepoRemoveCmd(b)
if err := cmd.RunE(cmd, []string{repoFoo, repoBar}); err != nil { if err := cmd.RunE(cmd, []string{repoFoo, repoBar}); err != nil {
t.Error(err) t.Error(err)
} }

@ -46,7 +46,8 @@ type repoUpdateCmd struct {
strict bool strict bool
} }
func newRepoUpdateCmd(out io.Writer) *cobra.Command { // NewRepoUpdateCmd returns cobra.Command to update information about available charts locally from chart repositories
func NewRepoUpdateCmd(out io.Writer) *cobra.Command {
u := &repoUpdateCmd{ u := &repoUpdateCmd{
out: out, out: out,
update: updateCharts, update: updateCharts,

@ -121,7 +121,7 @@ func TestUpdateCmdStrictFlag(t *testing.T) {
settings.Home = thome settings.Home = thome
out := bytes.NewBuffer(nil) out := bytes.NewBuffer(nil)
cmd := newRepoUpdateCmd(out) cmd := NewRepoUpdateCmd(out)
cmd.ParseFlags([]string{"--strict"}) cmd.ParseFlags([]string{"--strict"})
if err := cmd.RunE(cmd, []string{}); err == nil { if err := cmd.RunE(cmd, []string{}); err == nil {

@ -48,7 +48,8 @@ type resetCmd struct {
kubeClient kubernetes.Interface kubeClient kubernetes.Interface
} }
func newResetCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewResetCmd returns cobra.Command to uninstalls Tiller from a cluster
func NewResetCmd(client helm.Interface, out io.Writer) *cobra.Command {
d := &resetCmd{ d := &resetCmd{
out: out, out: out,
client: client, client: client,

@ -49,7 +49,8 @@ type rollbackCmd struct {
description string description string
} }
func newRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command { // NewRollbackCmd returns cobra.Command to roll back a release to a previous revision
func NewRollbackCmd(c helm.Interface, out io.Writer) *cobra.Command {
rollback := &rollbackCmd{ rollback := &rollbackCmd{
out: out, out: out,
client: c, client: c,

@ -59,7 +59,7 @@ func TestRollbackCmd(t *testing.T) {
} }
cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command { cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newRollbackCmd(c, out) return NewRollbackCmd(c, out)
} }
runReleaseCases(t, tests, cmd) runReleaseCases(t, tests, cmd)

@ -50,7 +50,8 @@ type searchCmd struct {
colWidth uint colWidth uint
} }
func newSearchCmd(out io.Writer) *cobra.Command { // NewSearchCmd returns cobra.Command to search for a keyword in charts
func NewSearchCmd(out io.Writer) *cobra.Command {
sc := &searchCmd{out: out} sc := &searchCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -92,6 +92,6 @@ func TestSearchCmd(t *testing.T) {
settings.Home = "testdata/helmhome" settings.Home = "testdata/helmhome"
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newSearchCmd(out) return NewSearchCmd(out)
}) })
} }

@ -49,7 +49,8 @@ type serveCmd struct {
repoPath string repoPath string
} }
func newServeCmd(out io.Writer) *cobra.Command { // NewServeCmd returns cobra.Command to start a local http web server
func NewServeCmd(out io.Writer) *cobra.Command {
srv := &serveCmd{out: out} srv := &serveCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "serve", Use: "serve",

@ -53,7 +53,8 @@ type statusCmd struct {
outfmt string outfmt string
} }
func newStatusCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewStatusCmd returns cobra.Command to displays the status of the named release
func NewStatusCmd(client helm.Interface, out io.Writer) *cobra.Command {
status := &statusCmd{ status := &statusCmd{
out: out, out: out,
client: client, client: client,

@ -128,7 +128,7 @@ func TestStatusCmd(t *testing.T) {
} }
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newStatusCmd(c, out) return NewStatusCmd(c, out)
}) })
} }

@ -78,7 +78,8 @@ type templateCmd struct {
outputDir string outputDir string
} }
func newTemplateCmd(out io.Writer) *cobra.Command { // NewTemplateCmd returns cobra.Command to locally render templates
func NewTemplateCmd(out io.Writer) *cobra.Command {
t := &templateCmd{ t := &templateCmd{
out: out, out: out,

@ -188,7 +188,7 @@ func TestTemplateCmd(t *testing.T) {
os.Stdout = w os.Stdout = w
// execute template command // execute template command
out := bytes.NewBuffer(nil) out := bytes.NewBuffer(nil)
cmd := newTemplateCmd(out) cmd := NewTemplateCmd(out)
cmd.SetArgs(tt.args) cmd.SetArgs(tt.args)
err := cmd.Execute() err := cmd.Execute()

@ -118,7 +118,8 @@ type upgradeCmd struct {
caFile string caFile string
} }
func newUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command { // NewUpgradeCmd returns cobra.Command to upgrade a release
func NewUpgradeCmd(client helm.Interface, out io.Writer) *cobra.Command {
upgrade := &upgradeCmd{ upgrade := &upgradeCmd{
out: out, out: out,

@ -186,7 +186,7 @@ func TestUpgradeCmd(t *testing.T) {
} }
cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command { cmd := func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newUpgradeCmd(c, out) return NewUpgradeCmd(c, out)
} }
runReleaseCases(t, tests, cmd) runReleaseCases(t, tests, cmd)

@ -42,7 +42,8 @@ type verifyCmd struct {
out io.Writer out io.Writer
} }
func newVerifyCmd(out io.Writer) *cobra.Command { // NewVerifyCmd returns cobra.Command to verify that a chart at the given path has been signed and is valid
func NewVerifyCmd(out io.Writer) *cobra.Command {
vc := &verifyCmd{out: out} vc := &verifyCmd{out: out}
cmd := &cobra.Command{ cmd := &cobra.Command{

@ -74,7 +74,7 @@ func TestVerifyCmd(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
b := bytes.NewBuffer(nil) b := bytes.NewBuffer(nil)
vc := newVerifyCmd(b) vc := NewVerifyCmd(b)
vc.ParseFlags(tt.flags) vc.ParseFlags(tt.flags)
err := vc.RunE(vc, tt.args) err := vc.RunE(vc, tt.args)
if tt.err { if tt.err {

@ -58,7 +58,8 @@ type versionCmd struct {
template string template string
} }
func newVersionCmd(c helm.Interface, out io.Writer) *cobra.Command { // NewVersionCmd returns cobra.Command to print the client/server version information
func NewVersionCmd(c helm.Interface, out io.Writer) *cobra.Command {
version := &versionCmd{ version := &versionCmd{
client: c, client: c,
out: out, out: out,

@ -66,6 +66,6 @@ func TestVersion(t *testing.T) {
} }
settings.TillerHost = "fake-localhost" settings.TillerHost = "fake-localhost"
runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command { runReleaseCases(t, tests, func(c *helm.FakeClient, out io.Writer) *cobra.Command {
return newVersionCmd(c, out) return NewVersionCmd(c, out)
}) })
} }

Loading…
Cancel
Save