Start making env

feature/env
dtluna 6 years ago
parent 35fa871fdb
commit 593adb4cdf
  1. 18
      common.go
  2. 21
      env/env.go
  3. 12
      printenv/printenv.go

@ -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

@ -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()
}

@ -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)
}

Loading…
Cancel
Save