Start making env

This commit is contained in:
dtluna 2019-03-26 14:13:21 +03:00
parent 35fa871fdb
commit 593adb4cdf
3 changed files with 42 additions and 9 deletions

18
common.go Normal file
View File

@ -0,0 +1,18 @@
package coreutils
import (
"fmt"
"os"
)
// PrintStrings prints each string in strings on a new line
func PrintStrings(strings []string) {
for _, str := range strings {
fmt.Println(str)
}
}
// PrintEnv prints all environment variables
func PrintEnv() {
PrintStrings(os.Environ())
}

21
env/env.go vendored Normal file
View File

@ -0,0 +1,21 @@
package main
import (
"flag"
"os"
common "source.heropunch.io/tomo/go-coreutils"
)
var ignoreEnv = flag.Bool(
"i",
false,
"Completely ignore the existing environment and execute cmd only with each (var, value) tuple specified.",
)
func main() {
flag.Parse()
if *ignoreEnv {
os.Clearenv()
}
common.PrintEnv()
}

View File

@ -1,19 +1,13 @@
package main
import (
"fmt"
"os"
common "source.heropunch.io/tomo/go-coreutils"
)
func printStrings(strings []string) {
for _, str := range strings {
fmt.Println(str)
}
}
func main() {
if len(os.Args) == 1 {
printStrings(os.Environ())
common.PrintEnv()
os.Exit(0)
}
@ -27,6 +21,6 @@ func main() {
exitCode = 1
}
}
printStrings(envVars)
common.PrintStrings(envVars)
os.Exit(exitCode)
}