Skip to content

Commit

Permalink
chore: remove huawei resouce
Browse files Browse the repository at this point in the history
  • Loading branch information
nonzzz committed May 31, 2023
1 parent 9b6cc1e commit 86758c7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/manifoldco/promptui v0.9.0
github.com/nonzzz/ini v0.0.0-20230414084939-6d92cdc1bd80
github.com/nonzzz/ini v0.0.0-20230531091757-a15bda4e5a8b
)

require github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/edsrzf/mmap-go v1.1.0 h1:6EUwBLQ/Mcr1EYLE4Tn1VdW1A4ckqCQWZBw8Hr0kjpQ=
github.com/edsrzf/mmap-go v1.1.0/go.mod h1:19H/e8pUPLicwkyNgOykDXkJ9F0MHE+Z52B8EIth78Q=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/nonzzz/ini v0.0.0-20230414084939-6d92cdc1bd80 h1:cehvgmhwj93LSOz29UgoixAPnd2q5rX6u+nuM/73GBw=
github.com/nonzzz/ini v0.0.0-20230414084939-6d92cdc1bd80/go.mod h1:t0R1dkD281akpQ0TfHjEnpST6FaY50g8ix538IeLFhc=
github.com/nonzzz/ini v0.0.0-20230531091757-a15bda4e5a8b h1:8Itse4wlbyEwusdxzU4Y+6SdntyPtUFYHctSMSCGDi8=
github.com/nonzzz/ini v0.0.0-20230531091757-a15bda4e5a8b/go.mod h1:t0R1dkD281akpQ0TfHjEnpST6FaY50g8ix538IeLFhc=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
14 changes: 4 additions & 10 deletions internal/source/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,21 @@ type S uint8
const (
Npm S = iota
Yarn
HuaWei
Tencent
NpmMirror
System
)

var DefaultSource = map[string]S{
"https://registry.npmjs.org/": Npm,
"https://registry.yarnpkg.com/": Yarn,
"https://repo.huaweicloud.com/repository/npm/": HuaWei,
"https://mirrors.cloud.tencent.com/npm/": Tencent,
"https://registry.npmmirror.com/": NpmMirror,
"https://registry.npmjs.org/": Npm,
"https://registry.yarnpkg.com/": Yarn,
"https://mirrors.cloud.tencent.com/npm/": Tencent,
"https://registry.npmmirror.com/": NpmMirror,
}

var DefaultKey = map[S]string{
Npm: "https://registry.npmjs.org/",
Yarn: "https://registry.yarnpkg.com/",
HuaWei: "https://repo.huaweicloud.com/repository/npm/",
Tencent: "https://mirrors.cloud.tencent.com/npm/",
NpmMirror: "https://registry.npmmirror.com/",
}
Expand All @@ -46,8 +43,6 @@ func EnsureDefaultKey(input string) S {
s = Npm
case Yarn.String():
s = Yarn
case HuaWei.String():
s = HuaWei
case Tencent.String():
s = Tencent
case NpmMirror.String():
Expand All @@ -61,7 +56,6 @@ func EnsureDefaultKey(input string) S {
var SourceToString = []string{
"npm",
"yarn",
"huawei",
"tencet",
"npmMirror",
"system",
Expand Down
59 changes: 27 additions & 32 deletions internal/source/ini.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,51 @@
package source

import (
"fmt"
"strings"

"github.com/nonzzz/ini"
"github.com/nonzzz/ini/pkg/ast"
)

type GrmIniVisitor struct {
key string
val string
ini.IniVisitor
}

func (v *GrmIniVisitor) Expression(node *ast.Expression) {
if node.Key == v.key {
if v.val == "" {
v.val = node.Value
return
}
node.Value = v.val
}
}

type GrmIni struct {
Path string
ini *ini.Ini
}

func NewGrmIniParse(conf *GrmConfig) *GrmIni {
p := &GrmIni{
ini: ini.New(),
}
p.ini.LoadFile(conf.ConfPath)
p := &GrmIni{}
i, _ := ini.New().LoadFile(conf.ConfPath)
p.ini = i
return p
}

func (i *GrmIni) Set(k, v string) bool {
i.ini.Accept(&GrmIniVisitor{
key: k,
val: v,
i.ini.Walk(func(node, _ ast.Node) {
switch t := node.(type) {
case *ast.ExpressionNode:
if t.Key == k {
t.Text = fmt.Sprintf("%s = %s", k, v)
}
}
})
return i.ini.Err() == nil
return true
}

func (i *GrmIni) Get(k string) string {
v := &GrmIniVisitor{
key: k,
}
i.ini.Accept(v)
i.Path = v.val
return v.val
func (i *GrmIni) Get(k string) (val string) {
i.ini.Walk(func(node, _ ast.Node) {
switch t := node.(type) {
case *ast.ExpressionNode:
if t.Key == k {
val = strings.TrimSpace(t.Value)
}
}
})
i.Path = val
return val
}

func (i *GrmIni) ToString() string {
return i.ini.String()
s, _ := i.ini.Printer()
return s
}

0 comments on commit 86758c7

Please sign in to comment.