mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-14 02:57:52 +08:00
main: add envAsMap, in symmetry with envAsSlice
This commit is contained in:
parent
ca3294d42f
commit
eca1bbca1f
19
main/main.go
19
main/main.go
|
@ -65,6 +65,17 @@ func envAsSlice(env map[string]string) (s []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func envAsMap(env []string) (m map[string]string) {
|
||||
m = make(map[string]string)
|
||||
for _, e := range env {
|
||||
arr := strings.SplitN(e, "=", 2)
|
||||
if len(arr) == 2 {
|
||||
m[arr[0]] = arr[1]
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func evalTerm(n parse.Node) string {
|
||||
return n.(*parse.StringNode).Text
|
||||
}
|
||||
|
@ -78,13 +89,7 @@ func evalCommandArgs(n *parse.CommandNode) (args []string) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
env = make(map[string]string)
|
||||
for _, e := range os.Environ() {
|
||||
arr := strings.SplitN(e, "=", 2)
|
||||
if len(arr) == 2 {
|
||||
env[arr[0]] = arr[1]
|
||||
}
|
||||
}
|
||||
env := envAsMap(os.Environ())
|
||||
|
||||
path_var, ok := env["PATH"]
|
||||
if ok {
|
||||
|
|
Loading…
Reference in New Issue
Block a user