From a2ab1aaa09300186bd9d137e794c9b8a24313ff1 Mon Sep 17 00:00:00 2001 From: Louis Taylor Date: Tue, 21 Mar 2017 14:40:00 +0000 Subject: [PATCH] fix(helm): add --destination flag to 'helm package' This adds a flag similar to the --destination flag on 'helm fetch', allowing control over the destination for the packaged .tgz file. Closes #2117 --- cmd/helm/package.go | 36 +++++++++++++++++++++++------------- cmd/helm/package_test.go | 18 ++++++++++++++++++ 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/cmd/helm/package.go b/cmd/helm/package.go index ac8ff9d8e..100a4663d 100644 --- a/cmd/helm/package.go +++ b/cmd/helm/package.go @@ -48,14 +48,16 @@ Versioned chart archives are used by Helm package repositories. ` type packageCmd struct { - save bool - sign bool - path string - key string - keyring string - version string - out io.Writer - home helmpath.Home + save bool + sign bool + path string + key string + keyring string + version string + destination string + + out io.Writer + home helmpath.Home } func newPackageCmd(out io.Writer) *cobra.Command { @@ -96,6 +98,7 @@ func newPackageCmd(out io.Writer) *cobra.Command { f.StringVar(&pkg.key, "key", "", "name of the key to use when signing. Used if --sign is true") f.StringVar(&pkg.keyring, "keyring", defaultKeyring(), "location of a public keyring") f.StringVar(&pkg.version, "version", "", "set the version on the chart to this semver version") + f.StringVarP(&pkg.destination, "destination", "d", ".", "location to write the chart.") return cmd } @@ -129,12 +132,19 @@ func (p *packageCmd) run(cmd *cobra.Command, args []string) error { checkDependencies(ch, reqs, p.out) } - // Save to the current working directory. - cwd, err := os.Getwd() - if err != nil { - return err + var dest string + if p.destination == "." { + // Save to the current working directory. + dest, err = os.Getwd() + if err != nil { + return err + } + } else { + // Otherwise save to set destination + dest = p.destination } - name, err := chartutil.Save(ch, cwd) + + name, err := chartutil.Save(ch, dest) if err == nil && flagDebug { fmt.Fprintf(p.out, "Saved %s to current directory\n", name) } diff --git a/cmd/helm/package_test.go b/cmd/helm/package_test.go index a9dc021a3..340da0fdb 100644 --- a/cmd/helm/package_test.go +++ b/cmd/helm/package_test.go @@ -94,6 +94,20 @@ func TestPackage(t *testing.T) { expect: "", hasfile: "alpine-0.1.0.tgz", }, + { + name: "package --destination toot", + args: []string{"testdata/testcharts/alpine"}, + flags: map[string]string{"destination": "toot"}, + expect: "", + hasfile: "toot/alpine-0.1.0.tgz", + }, + { + name: "package --destination does-not-exist", + args: []string{"testdata/testcharts/alpine"}, + flags: map[string]string{"destination": "does-not-exist"}, + expect: "stat does-not-exist: no such file or directory", + err: true, + }, { name: "package --sign --key=KEY --keyring=KEYRING testdata/testcharts/alpine", args: []string{"testdata/testcharts/alpine"}, @@ -124,6 +138,10 @@ func TestPackage(t *testing.T) { t.Fatal(err) } + if err := os.Mkdir("toot", 0777); err != nil { + t.Fatal(err) + } + ensureTestHome(helmpath.Home(tmp), t) oldhome := homePath() helmHome = tmp