cmd

package
v0.0.0-...-d7fa7f5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "gump",
	Short: "Bump your project version into any file",
	Long: `Sometimes there is no easy way to update the references to your sofware version. Gump will do it for you!

		Given a simple configuration file (default is $PWD/gump.yml):

			version: 0.1.0
			files:
			- path: file/test_files/yet-another-configuration-file.yml
				keys:
				- info.extra.version
				prefix: 'docker-image:'

		Just do
			gump

		If you need to bump your major version
		  gump -M

`,

	Run: func(cmd *cobra.Command, args []string) {
		// TODO: Use viper Get functions insead of hardcoding
		var locations []string
		version := viper.Get("version").(string)
		newVersion, err := bumpVersion(cmd, version)
		if err != nil {
			fmt.Println("error:", err)
			return
		}
		files := viper.Get("files").([]interface{})
		for _, v := range files {
			var prefix string
			if infprefix := v.(map[interface{}]interface{})["prefix"]; infprefix != nil {
				prefix = infprefix.(string)
			}
			newVersionWithPrefix := prefix + newVersion
			ls := v.(map[interface{}]interface{})["keys"].([]interface{})
			for i := 0; i < len(ls); i++ {
				locations = append(locations, ls[i].(string))
			}
			f, err := file.Read(v.(map[interface{}]interface{})["path"].(string))
			if err != nil {
				fmt.Println("error:", err)
				return
			}

			err = f.Modify(newVersionWithPrefix, locations)
			if err != nil {
				fmt.Println("error:", err)
				return
			}
		}
		newConf := &configuration.Configuration{}
		viper.Set("version", newVersion)
		viper.Unmarshal(newConf)
		err = newConf.Write(viper.ConfigFileUsed())
		if err != nil {
			fmt.Println("error while updating the gump conf file")
		}
	},
}

RootCmd represents the base command when called without any subcommands

Functions

func Execute

func Execute()

Execute adds all child commands to the root command sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址