Example #1
0
/*
 Find NodeDetail by node version

 Param:
    - url: index.json url, e.g. http://npm.taobao.org/mirrors/node/index.json
    - ver: node version. e.g. 5.9.0

 Return:
    - *NodeDetail: nodedetail struct
    - error

*/
func FindNodeDetailByVer(url, ver string) (*NodeDetail, error) {
	filter, err := util.FormatWildcard(ver, url)
	if err != nil {
		return nil, err
	}
	nodist, err, _ := New(url, filter)
	if err != nil {
		return nil, err
	}
	if len(nodist.nl) == 1 {
		nd := nodist.nl["v"+ver]
		return &nd, nil
	}
	return nil, nil
}
Example #2
0
/*
 Search Node.js version and Print

 Param:
 	- s: Node.js version, inlcude: *.*.* 0.*.* 0.10.* /<regexp>/ latest 0.10.10

*/
func Search(s string) {
	regex, err := util.FormatWildcard(s, latURL)
	if err != nil {
		P(ERROR, "%v not an %v Node.js version.\n", s, "valid")
		return
	}

	// set url
	url := config.GetConfig(config.REGISTRY)
	if arr := strings.Split(s, "."); len(arr) == 3 {
		if ver, _ := strconv.Atoi(arr[0]); ver >= 1 && ver <= 3 {
			url = config.GetIOURL(url)
		}
	}
	url += util.NODELIST

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

	// print
	P(DEFAULT, "Search Node.js version rules [%v] from %v, please wait.\n", s, url)

	// generate nodist
	nodist, err, code := New(url, regex)
	if err != nil {
		if code == -1 {
			P(ERROR, "'%v' get url %v error, Error: %v\n", "gnvm search", url, err)
		} else {
			P(ERROR, "%v an error has occurred. please check. Error: %v\n", "gnvm search", err)
		}
		return
	}

	if len(nodist.nl) > 0 {
		nodist.Detail(0)
	} else {
		P(WARING, "not search any Node.js version details, use rules [%v] from %v.\n", s, url)
	}
}