update
This commit is contained in:
@@ -95,12 +95,14 @@ func init() {
|
|||||||
f["JD_CASH_SHARECODES"] = e[k]
|
f["JD_CASH_SHARECODES"] = e[k]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
envs := []qinglong.Env{}
|
||||||
for i := range f {
|
for i := range f {
|
||||||
qinglong.SetEnv(qinglong.Env{
|
envs = append(envs, qinglong.Env{
|
||||||
Name: i,
|
Name: i,
|
||||||
Value: f[i],
|
Value: f[i],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
qinglong.SetEnv(envs...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-32
@@ -70,46 +70,48 @@ func GetEnvs(searchValue string) ([]Env, error) {
|
|||||||
return envs, nil
|
return envs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetEnv(env Env) error {
|
func SetEnv(envs ...Env) error {
|
||||||
config, err := GetConfig()
|
config, err := GetConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
lines := strings.Split(config, "\n")
|
lines := strings.Split(config, "\n")
|
||||||
set := false
|
for _, env := range envs {
|
||||||
for j, line := range lines {
|
set := false
|
||||||
for i, pattern := range []string{`^\s*export\s+([^'"=\s]+)=[ '"]?(.*?)['"]?$`, `^\s*#[#\s]*export\s+([^'"=\s]+)=[ '"]?(.*?)['"]?$`, `^\s*([^'"=\s]+)=[ '"]?(.*?)['"]?$`, `^\s*#[#\s]*([^'"=\s]+)=[ '"]?(.*?)['"]?$`} {
|
for j, line := range lines {
|
||||||
if v := regexp.MustCompile(pattern).FindStringSubmatch(line); len(v) > 0 {
|
for i, pattern := range []string{`^\s*export\s+([^'"=\s]+)=[ '"]?(.*?)['"]?$`, `^\s*#[#\s]*export\s+([^'"=\s]+)=[ '"]?(.*?)['"]?$`, `^\s*([^'"=\s]+)=[ '"]?(.*?)['"]?$`, `^\s*#[#\s]*([^'"=\s]+)=[ '"]?(.*?)['"]?$`} {
|
||||||
e := Env{}
|
if v := regexp.MustCompile(pattern).FindStringSubmatch(line); len(v) > 0 {
|
||||||
if i == 1 || i == 3 {
|
e := Env{}
|
||||||
e.Status = 1
|
if i == 1 || i == 3 {
|
||||||
|
e.Status = 1
|
||||||
|
}
|
||||||
|
e.Name = v[1]
|
||||||
|
e.Value = v[2]
|
||||||
|
if env.Name != e.Name {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if env.Value != e.Value {
|
||||||
|
e.Value = env.Value
|
||||||
|
}
|
||||||
|
if env.Status != e.Status {
|
||||||
|
e.Status = env.Status
|
||||||
|
}
|
||||||
|
h := ""
|
||||||
|
if e.Status == 1 {
|
||||||
|
h = "# "
|
||||||
|
}
|
||||||
|
if i <= 1 {
|
||||||
|
h = "export "
|
||||||
|
}
|
||||||
|
lines[j] = h + fmt.Sprintf("%s=\"%s\"", e.Name, e.Value)
|
||||||
|
set = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
e.Name = v[1]
|
|
||||||
e.Value = v[2]
|
|
||||||
if env.Name != e.Name {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if env.Value != e.Value {
|
|
||||||
e.Value = env.Value
|
|
||||||
}
|
|
||||||
if env.Status != e.Status {
|
|
||||||
e.Status = env.Status
|
|
||||||
}
|
|
||||||
h := ""
|
|
||||||
if e.Status == 1 {
|
|
||||||
h = "# "
|
|
||||||
}
|
|
||||||
if i <= 1 {
|
|
||||||
h = "export "
|
|
||||||
}
|
|
||||||
lines[j] = h + fmt.Sprintf("%s=\"%s\"", e.Name, e.Value)
|
|
||||||
set = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if !set {
|
||||||
if !set {
|
lines = append(lines, fmt.Sprintf("export %s=\"%s\"", env.Name, env.Value))
|
||||||
lines = append(lines, fmt.Sprintf("export %s=\"%s\"", env.Name, env.Value))
|
}
|
||||||
}
|
}
|
||||||
return SvaeConfig(strings.Join(lines, "\n"))
|
return SvaeConfig(strings.Join(lines, "\n"))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user