Skip to content

Instantly share code, notes, and snippets.

@alexellis
Created March 5, 2020 18:53
Show Gist options
  • Save alexellis/ec11526dac477b2fcad5e00925cc0286 to your computer and use it in GitHub Desktop.
Save alexellis/ec11526dac477b2fcad5e00925cc0286 to your computer and use it in GitHub Desktop.
go-hello-flags-env.go
package main
import (
"flag"
"fmt"
"os"
)
func main() {
var printUser bool
flag.BoolVar(&printUser, "print-user", true, "Print a name if set to true")
flag.Parse()
user := os.Getenv("USER")
if printUser {
fmt.Printf("Hello %s\n", user)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment