Start making env
This commit is contained in:
parent
35fa871fdb
commit
593adb4cdf
18
common.go
Normal file
18
common.go
Normal 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
21
env/env.go
vendored
Normal 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()
|
||||
}
|
@ -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…
Reference in New Issue
Block a user