本文整理汇总了Golang中gnvm/config.GetConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang GetConfig函数的具体用法?Golang GetConfig怎么用?Golang GetConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetConfig函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
noderoot = config.GetConfig(config.NODEROOT)
nodehome = os.Getenv(NODE_HOME)
if nodehome == "" && config.GetConfig(config.GLOBAL_VERSION) == util.UNKNOWN {
P(NOTICE, "not found environment variable '%v', please use '%v'. See '%v'.\n", NODE_HOME, "gnvm reg noderoot", "gnvm help reg")
}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:7,代码来源:regedit.go
示例2: Update
/*
Update local Node.js latest verion
- localVersion, remoteVersion: string Node.js version
- local, remote: float64 Node.js version
Param:
- global: when global == true, call Use func.
*/
func Update(global bool) {
// try catch
defer func() {
if err := recover(); err != nil {
msg := fmt.Sprintf("'%v' an error has occurred. \nError: ", "gnvm updte latest")
Error(ERROR, msg, err)
os.Exit(0)
}
}()
localVersion, remoteVersion := config.GetConfig(config.LATEST_VERSION), util.GetLatVer(latURL)
P(NOTICE, "local Node.js latest version is %v.\n", localVersion)
if remoteVersion == "" {
P(ERROR, "get latest version error, please check. See '%v'.\n", "gnvm help config")
return
}
P(NOTICE, "remote Node.js latest version is %v from %v.\n", remoteVersion, config.GetConfig("registry"))
local, remote, args := util.FormatNodeVer(localVersion), util.FormatNodeVer(remoteVersion), []string{remoteVersion}
switch {
case localVersion == util.UNKNOWN:
if code := InstallNode(args, global); code == 0 {
config.SetConfig(config.LATEST_VERSION, remoteVersion)
P(DEFAULT, "Update Node.js latest success, current latest version is %v.\n", remoteVersion)
}
case local == remote:
if util.IsDirExist(rootPath + localVersion) {
cp := CP{Red, false, None, false, "="}
P(DEFAULT, "Remote latest version %v %v latest version %v, don't need to upgrade.\n", remoteVersion, cp, localVersion)
if global {
if ok := Use(localVersion); ok {
config.SetConfig(config.GLOBAL_VERSION, localVersion)
}
}
} else {
P(WARING, "%v folder is not exist. See '%v'.\n", localVersion, "gnvm ls")
if code := InstallNode(args, global); code == 0 {
P(DEFAULT, "Local Node.js latest version is %v.\n", localVersion)
}
}
case local > remote:
cp := CP{Red, false, None, false, ">"}
P(WARING, "local latest version %v %v remote latest version %v.\nPlease check your config %v. See '%v'.\n", localVersion, cp, remoteVersion, "registry", "gnvm help config")
case local < remote:
cp := CP{Red, false, None, false, ">"}
P(WARING, "remote latest version %v %v local latest version %v.\n", remoteVersion, cp, localVersion)
if code := InstallNode(args, global); code == 0 {
config.SetConfig(config.LATEST_VERSION, remoteVersion)
P(DEFAULT, "Update success, Node.js latest version is %v.\n", remoteVersion)
}
}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:65,代码来源:nodehandle.go
示例3: NodeVersion
func NodeVersion(args []string, remote bool) {
// try catch
defer func() {
if err := recover(); err != nil {
msg := fmt.Sprintf("'gnvm node-version %v' an error has occurred. please check. \nError: ", strings.Join(args, " "))
Error(ERROR, msg, err)
os.Exit(0)
}
}()
latest := config.GetConfig(config.LATEST_VERSION)
global := config.GetConfig(config.GLOBAL_VERSION)
if len(args) == 0 || len(args) > 1 {
P(DEFAULT, "Node.exe %v version is %v.\n", "latest", latest)
P(DEFAULT, "Node.exe %v version is %v.\n", "global", global)
} else {
switch {
case args[0] == "global":
P(DEFAULT, "Node.exe global version is %v.\n", global)
case args[0] == "latest" && !remote:
P(DEFAULT, "Node.exe latest version is %v.\n", latest)
case args[0] == "latest" && remote:
remoteVersion := getLatestVersionByRemote()
if remoteVersion == "" {
P(ERROR, "get remote %v latest version error, please check. See '%v'.\n", config.GetConfig("registry")+config.LATEST+"/"+config.NODELIST, "gnvm help config")
P(DEFAULT, "Node.exe latest version is %v.\n", latest)
return
}
P(DEFAULT, "Node.exe remote %v version is %v.\n", config.GetConfig("registry"), remoteVersion)
P(DEFAULT, "Node.exe latest version is %v.\n", latest)
}
}
isPrint := false
switch {
case len(args) == 0 && (global == config.UNKNOWN || latest == config.UNKNOWN):
isPrint = true
case len(args) > 0 && args[0] == "latest" && latest == config.UNKNOWN:
isPrint = true
case len(args) > 0 && args[0] == "global" && global == config.UNKNOWN:
isPrint = true
}
if isPrint {
P(WARING, "when version is %v, please use '%v'. See '%v'.\n", config.UNKNOWN, "gnvm config INIT", "gnvm help config")
}
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:48,代码来源:nodehandle.go
示例4: TransLatestVersion
func TransLatestVersion(latest string, isPrint bool) string {
if latest == config.LATEST {
latest = config.GetConfig(config.LATEST_VERSION)
if isPrint {
P(NOTICE, "current latest version is %v.\n", latest)
}
}
return latest
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:9,代码来源:nodehandle.go
示例5: New
/*
Create NPMange
*/
func (this *NPMange) New() *NPMange {
this.root = config.GetConfig(config.NODEROOT)
this.modules = this.root + util.DIVIDE + "node_modules"
this.npmpath = this.modules + util.DIVIDE + util.NPM
this.npmbin = this.npmpath + util.DIVIDE + "bin"
this.command1 = "npm"
this.command2 = "npm.cmd"
return this
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:12,代码来源:npm.go
示例6: downloadNpm
/*
* return code
* 0: success
*
*/
func downloadNpm(version string) int {
// set url
url := config.GetConfig(config.REGISTRY) + "npm/" + version
// download
if code := curl.New(url, version, os.TempDir()+DIVIDE+version); code != 0 {
return code
}
return 0
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:17,代码来源:nodehandle.go
示例7: getLatestVersionByRemote
func getLatestVersionByRemote() string {
var version string
// set url
url := config.GetConfig("registry") + "latest/" + util.SHASUMS
version = util.GetLatestVersion(url)
return version
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:12,代码来源:nodehandle.go
示例8: LsRemote
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)
}
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:47,代码来源:nodehandle.go
示例9: Search
/*
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)
}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:52,代码来源:nodehandle.go
示例10: getNodeNpmVer
/*
Get npm version by global( local ) node version
Return:
- string: npm version
*/
func getNodeNpmVer() string {
ver, err := util.GetNodeVer(rootPath)
if err != nil {
panic(errors.New("not exist global node.exe. please usage 'gnvm install latest -g' frist."))
}
url := config.GetConfig(config.REGISTRY)
if level := util.GetNodeVerLev(util.FormatNodeVer(ver)); level == 3 {
url = config.GetIOURL(url)
}
url += util.NODELIST
nd, err := FindNodeDetailByVer(url, ver)
if err != nil {
panic(err)
}
return nd.NPM.Version
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:25,代码来源:npm.go
示例11: download
/*
* return code
* 0: success
* 1: remove folder error
* 2: folder exist
* 3: create folder error
*
*/
func download(version string) int {
// get current os arch
amd64 := "/"
if runtime.GOARCH == "amd64" {
amd64 = "/x64/"
}
// rootPath/version/node.exe is exist
if _, err := util.GetNodeVersion(rootPath + version + DIVIDE); err == nil {
P(WARING, "%v folder exist.\n", version)
return 2
} else {
if err := os.RemoveAll(rootPath + version); err != nil {
P(ERROR, "remove %v fail, Error: %v\n", version, err.Error())
return 1
}
//P(DEFAULT, "Remove empty [%v] folder success.\n", version)
}
// rootPath/version is exist
if isDirExist(rootPath+version) != true {
if err := os.Mkdir(rootPath+version, 0777); err != nil {
P(ERROR, "create %v fail, Error: %v\n", version, err.Error())
return 3
}
}
// set url
url := config.GetConfig(config.REGISTRY) + "v" + version + amd64 + NODE
// download
if code := curl.New(url, version, rootPath+version+DIVIDE+NODE); code != 0 {
if code == -1 {
if err := os.RemoveAll(rootPath + version); err != nil {
P(ERROR, "remove %v fail, Error: %v\n", version, err.Error())
return 1
}
}
return code
}
return 0
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:52,代码来源:nodehandle.go
示例12: downloadNpm
/*
Download / unzip / install npm
Param:
- ver: npm version
*/
func downloadNpm(ver string) {
version := "v" + ver + ZIP
url := NPMTAOBAO + version
if config.GetConfig(config.REGISTRY) != util.ORIGIN_TAOBAO {
url = NPMDEFAULT + version
}
// create npm
npm.New().SetZip(version)
P(DEFAULT, "Start download new npm version %v\n", version)
// download
if err := npm.Download(url, version); err != nil {
panic(err.Error())
}
P(DEFAULT, "Start unzip and install %v zip file, please wait.\n", version)
// create node_modules
npm.CreateModules()
// clean all npm files
npm.CleanAll()
// unzip
if _, err := npm.Unzip(); err != nil {
msg := fmt.Sprintf("unzip %v an error has occurred. \nError: ", npm.zipname, err.Error())
panic(errors.New(msg))
}
// install
if err := npm.Install(); err != nil {
return
}
// remove download zip file
npm.Clean(npm.zippath)
P(DEFAULT, "Set success, current npm version is %v.\n", ver)
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:48,代码来源:npm.go
示例13: LsRemote
/*
Print remote Node.js version list
Param:
- limit: print max line
- io: when io == true, print iojs
*/
func LsRemote(limit int, io bool) {
// set url
url := config.GetConfig(config.REGISTRY)
if io {
url = config.GetIOURL(url)
}
url += util.NODELIST
// try catch
defer func() {
if err := recover(); err != nil {
msg := fmt.Sprintf("'gnvm ls --remote' an error has occurred. please check your input %v. \nError: ", url)
Error(ERROR, msg, err)
os.Exit(0)
}
}()
// print
P(DEFAULT, "Read all Node.js version list from %v, please wait.\n", url)
// generate nodist
nodist, err, code := New(url, nil)
if err != nil {
if code == -1 {
P(ERROR, "'%v' get url %v error, Error: %v\n", "gnvm ls -r -d", url, err)
} else {
P(ERROR, "%v an error has occurred. please check your input. Error: %v\n", "gnvm ls -r -d", err)
}
return
}
if limit != -1 {
nodist.Detail(limit)
} else {
for _, v := range nodist.Sorts {
fmt.Println(v)
}
}
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:47,代码来源:nodehandle.go
示例14:
v = util.EqualAbs("npm", v)
if v == "npm" {
nodehandle.UninstallNPM()
continue
}
v = util.EqualAbs("ALL", v)
if v == "ALL" {
P(WARING, "'%v' not supported mixed parameters, please usage '%v'. See '%v'.\n", "gnvm uninstall ALL", "gnvm uninstall ALL", "gnvm help uninstall")
continue
}
v = util.EqualAbs("latest", v)
if v == util.LATEST {
util.FormatLatVer(&v, config.GetConfig(config.LATEST_VERSION), true)
}
// check version format
if !util.VerifyNodeVer(v) {
P(ERROR, "%v not an %v Node.js version.\n", v, "valid")
} else {
nodehandle.Uninstall(v)
}
}
},
}
// sub cmd
var useCmd = &cobra.Command{
Use: "use",
开发者ID:Kenshin,项目名称:gnvm,代码行数:30,代码来源:command.go
示例15: Update
func Update(global bool) {
// try catch
defer func() {
if err := recover(); err != nil {
Error(ERROR, "'gnvm updte latest' an error has occurred. \nError: ", err)
os.Exit(0)
}
}()
localVersion := config.GetConfig(config.LATEST_VERSION)
P(NOTICE, "local latest version is %v.\n", localVersion)
remoteVersion := getLatestVersionByRemote()
if remoteVersion == "" {
P(ERROR, "get latest version error, please check. See '%v'.\n", "gnvm help config")
return
}
P(NOTICE, "remote %v latest version is %v.\n", config.GetConfig("registry"), remoteVersion)
local, _ := util.ConverFloat(localVersion)
remote, _ := util.ConverFloat(remoteVersion)
var args []string
args = append(args, remoteVersion)
switch {
case localVersion == config.UNKNOWN:
P(WARING, "local latest version is %v.\n", config.UNKNOWN)
if code := Install(args, global); code == 0 || code == 2 {
config.SetConfig(config.LATEST_VERSION, remoteVersion)
P(DEFAULT, "Update latest success, current latest version is %v.\n", remoteVersion)
}
case local == remote:
if isDirExist(rootPath + localVersion) {
cp := CP{Red, false, None, false, "="}
P(DEFAULT, "Remote latest version %v %v latest version %v, don't need to upgrade.\n", remoteVersion, cp, localVersion)
if global {
if ok := Use(localVersion); ok {
config.SetConfig(config.GLOBAL_VERSION, localVersion)
}
}
} else if !isDirExist(rootPath + localVersion) {
P(WARING, "local not exist %v\n", localVersion)
if code := Install(args, global); code == 0 || code == 2 {
P(DEFAULT, "Download latest version %v success.\n", localVersion)
}
}
case local > remote:
cp := CP{Red, false, None, false, ">"}
P(WARING, "local latest version %v %v remote latest version %v.\nPlease check your registry. See 'gnvm help config'.\n", localVersion, cp, remoteVersion)
case local < remote:
cp := CP{Red, false, None, false, ">"}
P(WARING, "remote latest version %v %v local latest version %v.\n", remoteVersion, cp, localVersion)
if code := Install(args, global); code == 0 || code == 2 {
config.SetConfig(config.LATEST_VERSION, remoteVersion)
P(DEFAULT, "Update latest success, current latest version is %v.\n", remoteVersion)
}
}
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:62,代码来源:nodehandle.go
示例16: InstallNpm
func InstallNpm() {
// try catch
defer func() {
if err := recover(); err != nil {
if strings.HasPrefix(err.(string), "CURL Error:") {
fmt.Printf("\n")
}
Error(ERROR, "'gnvm install npm' an error has occurred. \nError: ", err)
os.Exit(0)
}
}()
out, err := exec.Command(rootPath+"npm", "--version").Output()
if err == nil {
P(WARING, "current path %v exist npm, version is %v", rootPath, string(out[:]), "\n")
return
}
url := config.GetConfig(config.REGISTRY) + "npm"
// get
code, res, _ := curl.Get(url)
if code != 0 {
return
}
// close
defer res.Body.Close()
maxTime, _ := time.Parse(TIMEFORMART, TIMEFORMART)
var maxVersion string
getNpmVersion := func(content string, line int) bool {
if strings.Index(content, `<a href="`) == 0 && strings.Contains(content, ".zip") {
// parse
newLine := strings.Replace(content, `<a href="`, "", -1)
newLine = strings.Replace(newLine, `</a`, "", -1)
newLine = strings.Replace(newLine, `">`, " ", -1)
// e.g. npm-1.3.9.zip npm-1.3.9.zip> 23-Aug-2013 21:14 1535885
orgArr := strings.Fields(newLine)
// e.g. npm-1.3.9.zip
version := orgArr[0:1][0]
// e.g. 23-Aug-2013 21:14
sTime := strings.Join(orgArr[2:len(orgArr)-1], " ")
// bubble sort
if t, err := time.Parse(TIMEFORMART, sTime); err == nil {
if t.Sub(maxTime).Seconds() > 0 {
maxTime = t
maxVersion = version
}
}
}
return false
}
if err := curl.ReadLine(res.Body, getNpmVersion); err != nil && err != io.EOF {
P(ERROR, "parse npm version Error: %v, from %v\n", err, url)
return
}
if maxVersion == "" {
P(ERROR, "get npm version fail from %v, please check. See '%v'.\n", url, "gnvm help config")
return
}
P(NOTICE, "the latest version is %v from %v.\n", maxVersion, config.GetConfig(config.REGISTRY))
// download zip
zipPath := os.TempDir() + DIVIDE + maxVersion
if code := downloadNpm(maxVersion); code == 0 {
P(DEFAULT, "Start unarchive file %v.\n", maxVersion)
//unzip(maxVersion)
if err := zip.UnarchiveFile(zipPath, config.GetConfig(config.NODEROOT), nil); err != nil {
panic(err)
}
P(DEFAULT, "End unarchive.\n")
}
// remove temp zip file
if err := os.RemoveAll(zipPath); err != nil {
P(ERROR, "remove zip file fail from %v, Error: %v.\n", zipPath, err.Error())
}
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:93,代码来源:nodehandle.go
示例17: InstallNode
/*
Install node
Param:
- args : install Node.js versions, include: x.xx.xx latest x.xx.xx-io-x86 x.xx.xx-x86
- global: when global == true, call Use func.
Return:
- code: dl[0].Code, usage 'gnvm update latest'
*/
func InstallNode(args []string, global bool) int {
localVersion, isLatest, code, dl, ts := "", false, 0, new(curl.Download), new(curl.Task)
// try catch
defer func() {
if err := recover(); err != nil {
if strings.HasPrefix(err.(string), "CURL Error:") {
fmt.Printf("\n")
}
msg := fmt.Sprintf("'gnvm install %v' an error has occurred. \nError: ", strings.Join(args, " "))
Error(ERROR, msg, err)
os.Exit(0)
}
}()
for _, v := range args {
ver, io, arch, suffix, err := util.ParseNodeVer(v)
if err != nil {
switch err.Error() {
case "1":
P(ERROR, "%v not node.exe download.\n", v)
case "2":
P(ERROR, "%v format error, suffix only must be '%v' or '%v'.\n", v, "x86", "x64")
case "3":
P(ERROR, "%v format error, parameter must be '%v' or '%v'.\n", v, "x.xx.xx", "x.xx.xx-x86|x64")
case "4":
P(ERROR, "%v not an %v Node.js version.\n", v, "valid")
case "5":
P(WARING, "'%v' command is no longer supported. See '%v'.\n", "gnvm install npm", "gnvm help npm")
}
continue
}
// when os is 386, not download 64 bit node.exe
if runtime.GOARCH == "386" && suffix == "x64" {
P(WARING, "current operating system is %v, not support %v suffix.\n", "32-bit", "x64")
continue
}
// check local latest and get remote latest
v = util.EqualAbs("latest", v)
if ver == util.LATEST {
localVersion = config.GetConfig(config.LATEST_VERSION)
P(NOTICE, "local latest version is %v.\n", localVersion)
version := util.GetLatVer(latURL)
if version == "" {
P(ERROR, "get latest version error, please check. See '%v'.\n", "gnvm config help")
break
}
isLatest = true
ver = version
P(NOTICE, "remote latest version is %v.\n", version)
} else {
isLatest = false
}
// ture folder name
if suffix != "" {
ver += "-" + suffix
}
// verify <root>/folder is exist
folder := rootPath + ver
if _, err := util.GetNodeVer(folder); err == nil {
P(WARING, "%v folder exist.\n", ver)
continue
}
// get and set url( include iojs)
url := config.GetConfig(config.REGISTRY)
if io {
url = config.GetIOURL(url)
}
// add task
if url, err := util.GetRemoteNodePath(url, ver, arch); err == nil {
dl.AddTask(ts.New(url, ver, util.NODE, folder))
}
}
// downlaod
if len(*dl) > 0 {
curl.Options.Header = false
arr := (*dl).GetValues("Title")
P(DEFAULT, "Start download Node.js versions [%v].\n", strings.Join(arr, ", "))
newDL, errs := curl.New(*dl)
//.........这里部分代码省略.........
开发者ID:Kenshin,项目名称:gnvm,代码行数:101,代码来源:nodehandle.go
示例18: init
func init() {
rootPath = util.GlobalNodePath + util.DIVIDE
latURL = config.GetConfig(config.REGISTRY) + util.LATEST + "/" + util.SHASUMS
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:4,代码来源:nodehandle.go
示例19: LS
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
}
开发者ID:GitHanDong,项目名称:gnvm,代码行数:76,代码来源:nodehandle.go
示例20: Use
/**
* rootPath : node.exe global path, e.g. x:\xxx\xx\xx\
*
* global : global node.exe version num, e.g. x.xx.xx-x86 ( only rumtime.GOARCH == "amd64", suffix include: 'x86' and 'x64' )
* globalPath : global node.exe version path, e.g. x:\xxx\xx\xx\x.xx.xx-x86
*
* newer : newer node.exe version num, e.g. x.xx.xx
* newerPath : newer node.exe version path, e.g. <rootPath>\x.xx.xx\
*
*/
func Use(newer string) bool {
// try catch
defer func() {
if err := recover(); err != nil {
msg := fmt.Sprintf("'gnvm use %v' an error has occurred. please check. \nError: ", newer)
Error(ERROR, msg, err)
os.Exit(0)
}
}()
// get true folder, e.g. folder is latest return x.xx.xx
util.FormatLatVer(&newer, config.GetConfig(config.LATEST_VERSION), true)
if newer == util.UNKNOWN {
P(WARING, "current latest is %v, please usage '%v' first. See '%v'.\n", newer, "gnvm update latest", "gnvm help update")
return false
}
// set newerPath and verify newerPath is exist?
newerPath := rootPath + newer
if _, err := util.GetNodeVer(newerPath); err != nil {
P(WARING, "%v folder is not exist %v, use '%v' get local Node.js version list. See '%v'.\n", newer, "node.exe", "gnvm ls", "gnvm help ls")
return false
}
// get <root>/node.exe version, when exist, get full version, e.g. x.xx.xx-x86
global, err := util.GetNodeVer(rootPath)
if err != nil {
P(WARING, "not found %v Node.js version.\n", "global")
} else {
if bit, err := util.Arch(rootPath); err == nil {
if bit == "x86" && runtime.GOARCH == "amd64" {
global += "-" + bit
}
}
}
// check newer is global
if newer == global {
P(WARING, "current Node.js version is %v, not re-use. See '%v'.\n", newer, "gnvm node-version")
return false
}
// set globalPath
globalPath := rootPath + global
// <root>/global is exist? when not exist, create global folder
if !util.IsDirExist(globalPath) {
if err := os.Mkdir(globalPath, 0777); err != nil {
P(ERROR, "create %v folder Error: %v.\n", global, err.Error())
return false
}
}
// backup copy <root>/node.exe to <root>/global/node.exe
if global != "" {
if err := util.Copy(rootPath, globalPath, util.NODE); err != nil {
P(ERROR, "copy %v to %v folder Error: %v.\n", rootPath, globalPath, err.Error())
return false
}
}
// copy <root>/newer/node.exe to <root>/node.exe
if err := util.Copy(newerPath, rootPath, util.NODE); err != nil {
P(ERROR, "copy %v to %v folder Error: %v.\n", newerPath, rootPath, err.Error())
return false
}
P(DEFAULT, "Set success, global Node.js version is %v.\n", newer)
return true
}
开发者ID:Kenshin,项目名称:gnvm,代码行数:82,代码来源:nodehandle.go
注:本文中的gnvm/config.GetConfig函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论