Example #1
0
	Short: "Use any version of the local already exists",
	Long: `Use any version of the local already exists e.g.
gnvm use x.xx.xx
gnvm use latest`,
	Run: func(cmd *cobra.Command, args []string) {
		if len(args) == 1 {

			args[0] = util.EqualAbs("latest", args[0])

			if args[0] != "latest" && util.VerifyNodeVersion(args[0]) != true {
				P(ERROR, "use parameter support '%v' or '%v', e.g. %v, please check your input. See '%v'.\n", "latest", "x.xx.xx", "0.10.28", "gnvm help use")
				return
			}

			// set use
			if ok := nodehandle.Use(args[0]); ok == true {
				config.SetConfig(config.GLOBAL_VERSION, nodehandle.TransLatestVersion(args[0], false))
			}
		} else {
			P(ERROR, "use parameter maximum is 1, please check your input. See '%v'.\n", "gnvm help use")
		}
	},
}

// sub cmd
var updateCmd = &cobra.Command{
	Use:   "update",
	Short: "Update latest node.exe",
	Long: `Update latest node.exe e.g.
gnvm update latest
gnvm update latest --global`,
Example #2
0
gnvm use x.xx.xx-x86  :Usage x.xx.xx Node.js with arch x86 version.
`,
	Run: func(cmd *cobra.Command, args []string) {
		if _, ok := util.IsSessionEnv("use", true); ok {
			return
		}
		if len(args) == 1 {
			version := args[0]
			version = util.EqualAbs("latest", version)
			if util.VerifyNodeVer(version) != true {
				P(ERROR, "%v param only support [%v] or %v e.g. [%v], please check your input. See '%v'.\n", "gnvm use", "latest", "valid Node.js version", "5.9.1", "gnvm help use")
				return
			}

			// set use
			if ok := nodehandle.Use(version); ok == true {
				util.FormatLatVer(&version, config.GetConfig(config.LATEST_VERSION), false)
				config.SetConfig(config.GLOBAL_VERSION, version)
			}
		} else {
			P(ERROR, "%v must be only %v parameter, please check your input. See '%v'.\n", "gnvm use", "one", "gnvm help use")
		}
	},
}

// sub cmd
var sessionCmd = &cobra.Command{
	Use:   "session",
	Short: "Set any local Node.js version to session Node.js version",
	Long: `
Set any Node.js version of the local already exists to session Node.js version, e.g. :