Skip to content

Commit

Permalink
Merge pull request #2 from mbenabda/feature/add_getversion_subcommand
Browse files Browse the repository at this point in the history
add the get subcommand to get a chart's version
  • Loading branch information
mbenabda authored Feb 26, 2018
2 parents ccb7ba1 + 037e25c commit be4c604
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
47 changes: 40 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import (
// Version identifier populated via the CI/CD process.
var Version = "HEAD"

type getVersionCommand struct {
chart string
out io.Writer
}

type setVersionCommand struct {
chart string
version string
Expand All @@ -30,6 +35,17 @@ type bumpVersionCommand struct {
out io.Writer
}

func (c *getVersionCommand) run() error {
chart, err := chartutil.Load(c.chart)
if err != nil {
return err
}

fmt.Fprint(c.out, chart.Metadata.Version)

return nil
}

func (c *setVersionCommand) run() error {
chart, err := chartutil.Load(c.chart)
if err != nil {
Expand Down Expand Up @@ -82,11 +98,30 @@ func (c *bumpVersionCommand) run() error {
return writeChartFile(chart, c.chart)
}

func newGetVersionCommand(out io.Writer) *cobra.Command {
gv := &getVersionCommand{out: out}

cmd := &cobra.Command{
Use: "get",
Short: "Print a local chart's version number",
RunE: func(cmd *cobra.Command, args []string) error {
return gv.run()
},
}

f := cmd.Flags()
f.StringVarP(&gv.chart, "chart", "c", "", "Path to a local chart's root directory")

cmd.MarkFlagRequired("chart")

return cmd
}

func newSetVersionCommand(out io.Writer) *cobra.Command {
sc := &setVersionCommand{out: out}

cmd := &cobra.Command{
Use: "set --chart [PATH_TO_CHART_DIRECTORY] --version [version]",
Use: "set",
Short: "Modify a local chart's version number in place",
RunE: func(cmd *cobra.Command, args []string) error {
return sc.run()
Expand All @@ -107,7 +142,7 @@ func newBumpVersionCommand(out io.Writer) *cobra.Command {
bc := &bumpVersionCommand{out: out}

cmd := &cobra.Command{
Use: "bump --chart [PATH_TO_CHART_DIRECTORY] --version-segment (major|minor|patch)",
Use: "bump",
Short: "Increment the desired segment of a local chart's version",
RunE: func(cmd *cobra.Command, args []string) error {
return bc.run()
Expand All @@ -116,7 +151,7 @@ func newBumpVersionCommand(out io.Writer) *cobra.Command {

f := cmd.Flags()
f.StringVarP(&bc.chart, "chart", "c", "", "Path to a local chart's root directory")
f.StringVarP(&bc.segment, "version-segment", "s", "", "segment of the chart's version to bump (major|minor|patch)")
f.StringVarP(&bc.segment, "version-segment", "s", "", "Segment of the chart's version to bump (major|minor|patch)")

cmd.MarkFlagRequired("chart")
cmd.MarkFlagRequired("version-segment")
Expand All @@ -132,18 +167,16 @@ func main() {

out := rootCmd.OutOrStdout()

fmt.Fprintln(out, "Helm local-chart-version Plugin --", Version)
fmt.Fprintln(out, "")

rootCmd.AddCommand(&cobra.Command{
Use: "version",
Short: "Print the version of the local-chart-version helm plugin",
Long: "All software has versions. This is helm-local-chart-version's",
Run: func(cmd *cobra.Command, args []string) {
fmt.Fprintln(out, "Helm local-chart-version Plugin --", Version)
fmt.Fprint(out, Version)
},
})

rootCmd.AddCommand(newGetVersionCommand(out))
rootCmd.AddCommand(newSetVersionCommand(out))
rootCmd.AddCommand(newBumpVersionCommand(out))

Expand Down
2 changes: 1 addition & 1 deletion plugin.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "local-chart-version"
version: "0.0.1"
version: "0.0.2"
usage: "local-chart-version [subcommand] LOCAL_CHART_DIRECTORY [flags]"
description: |-
Helm plugin for setting/bumping the version number of a local chart
Expand Down

0 comments on commit be4c604

Please sign in to comment.