Get the minimum viable of the command working.

Stripped debug code out
Tidied up some flag handling
Get it working with and without the -f flag.
This commit is contained in:
John Barton (joho) 2014-09-21 10:42:05 +10:00
parent 28b52615cf
commit 8c38c298ed

View File

@ -11,8 +11,10 @@ import (
)
func main() {
showHelp := *flag.Bool("h", false, "show help")
rawEnvFilenames := *flag.String("f", "", "comma separated paths to .env files")
var showHelp bool
flag.BoolVar(&showHelp, "h", false, "show help")
var rawEnvFilenames string
flag.StringVar(&rawEnvFilenames, "f", "", "comma separated paths to .env files")
flag.Parse()
@ -29,26 +31,28 @@ example
`
// if no args or -h flag
// print usage and return
if showHelp || len(os.Args) < 2 {
args := flag.Args()
if showHelp || len(args) == 0 {
fmt.Println(usage)
return
}
// load env
// TODO something in flag passing or whatever isn't quite right
// TODO would be nicer for an empty rawEnvFilenames to give us an empty map
// and then only call Load() once
// other TODO error handling on Load()
if rawEnvFilenames == "" {
godotenv.Load()
} else {
envFilenames := strings.Split(rawEnvFilenames, ",")
fmt.Printf("env filenames %v\n", envFilenames)
godotenv.Load(envFilenames...)
fmt.Printf("FOO=%v\n", os.Getenv("FOO"))
}
// take rest of args and "exec" them
args := flag.Args()
cmd := args[0]
cmdArgs := args[1:len(args)]
fmt.Printf("cmd %v with args: %v\n", cmd, cmdArgs)
command := exec.Command(cmd, cmdArgs...)
// command.Env = os.Environ()
command.Stdin = os.Stdin
command.Stdout = os.Stdout
command.Stderr = os.Stderr