Exemple #1
0
func LsRemote() {

	// set url
	url := config.GetConfig(config.REGISTRY) + config.NODELIST

	// try catch
	defer func() {
		if err := recover(); err != nil {
			msg := fmt.Sprintf("'gnvm ls --remote' an error has occurred. please check registry %v. \nError: ", url)
			Error(ERROR, msg, err)
			os.Exit(0)
		}
	}()

	// set exist version
	isExistVersion := false

	// print
	P(DEFAULT, "Read all node.exe version list from %v, please wait.\n", url)

	// get
	code, res, _ := curl.Get(url)
	if code != 0 {
		return
	}
	// close
	defer res.Body.Close()

	writeVersion := func(content string, line int) bool {
		// replace '\n'
		content = strings.Replace(content, "\n", "", -1)

		// split 'vx.xx.xx  1.1.0-alpha-2'
		args := strings.Split(content, " ")

		if ok := util.VerifyNodeVersion(args[0][1:]); ok {
			isExistVersion = true
			P(DEFAULT, args[0], "\n")
		}
		return false
	}

	if err := curl.ReadLine(res.Body, writeVersion); err != nil && err != io.EOF {
		P(ERROR, "%v Error: %v\n", "gnvm ls --remote", err)
	}

}
Exemple #2
0
func LS(isPrint bool) ([]string, error) {

	// try catch
	defer func() {
		if err := recover(); err != nil {
			Error(ERROR, "'gnvm ls' an error has occurred. please check. \nError: ", err)
			os.Exit(0)
		}
	}()

	var lsArr []string
	existVersion := false
	err := filepath.Walk(rootPath, func(dir string, f os.FileInfo, err error) error {

		// check nil
		if f == nil {
			return err
		}

		// check dir
		if f.IsDir() == false {
			return nil
		}

		// set version
		version := f.Name()

		// check node version
		if ok := util.VerifyNodeVersion(version); ok {

			// <root>/x.xx.xx/node.exe is exist
			if isDirExist(rootPath + version + DIVIDE + NODE) {
				desc := ""
				switch {
				case version == config.GetConfig(config.GLOBAL_VERSION) && version == config.GetConfig(config.LATEST_VERSION):
					desc = " -- global, latest"
				case version == config.GetConfig(config.LATEST_VERSION):
					desc = " -- latest"
				case version == config.GetConfig(config.GLOBAL_VERSION):
					desc = " -- global"
				}

				// set true
				existVersion = true

				// set lsArr
				lsArr = append(lsArr, version)

				if isPrint {
					if desc == "" {
						P(DEFAULT, "v"+version+desc, "\n")
					} else {
						P(DEFAULT, "%v", "v"+version+desc, "\n")
					}

				}
			}
		}

		// return
		return nil
	})

	// show error
	if err != nil {
		P(ERROR, "'%v' Error: %v.\n", "gnvm ls", err.Error())
		return lsArr, err
	}

	// version is exist
	if !existVersion {
		P(WARING, "don't have any available version, please check. See '%v'.\n", "gnvm help install")
	}

	return lsArr, err
}
Exemple #3
0
				v = util.EqualAbs("npm", v)

				// check npm
				if v == "npm" {
					P(WARING, "use format error, the correct format is '%v'. See '%v'.\n", "gnvm install npm", "gnvm help install")
					continue
				}

				// check latest
				if v == config.LATEST {
					newArgs = append(newArgs, v)
					continue
				}

				// check version format
				if ok := util.VerifyNodeVersion(v); ok != true {
					P(ERROR, "%v format error, the correct format is %v. \n", v, "x.xx.xx")
				} else {
					newArgs = append(newArgs, v)
				}
			}
			nodehandle.Install(newArgs, global)
		}
	},
}

// sub cmd
var uninstallCmd = &cobra.Command{
	Use:   "uninstall",
	Short: "Uninstall local node.exe version",
	Long: `Uninstall local node.exe version e.g.