summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorMitchell Riedstra <mitch@riedstra.dev>2025-05-03 09:53:52 -0400
committerMitchell Riedstra <mitch@riedstra.dev>2025-05-03 09:53:52 -0400
commit7dc357b940a44db7028940c106564de5408da42f (patch)
tree5518f8e2e80778605833ccde3ee2fa1410dd30a6 /main.go
parentc9047cfbc62191ccbe47c2ca0896eb4b192a7223 (diff)
downloadenvflag-master.tar.gz
envflag-master.tar.xz
Add a license and some docsHEADv0.0.1master
Diffstat (limited to 'main.go')
-rw-r--r--main.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/main.go b/main.go
index 8c50dc3..84dedb5 100644
--- a/main.go
+++ b/main.go
@@ -1,6 +1,35 @@
// Package envflag is an extremely small bit of code to make configuration
// via environment variables a little bit less of a hassle when using
// the flag package in the standard library.
+//
+// Example:
+//
+// package main
+//
+// import (
+// "flag"
+// "fmt"
+// "os"
+//
+// "riedstra.dev/go/envflag"
+// )
+//
+// func main() {
+// fl := flag.NewFlagSet("envflag", flag.ExitOnError)
+//
+// var aFlag string = "some default"
+// fmt.Println("aFlag:", aFlag)
+//
+// envflag.String(fl, &aFlag, "a", "FLAG_A", "Set's the value of -a")
+//
+// // By default, command line flags override environment vars.
+// fl.Parse(os.Args[1:])
+//
+// fmt.Println("aFlag:", aFlag)
+// }
+//
+// Known caveat, variables set in the environment will override what the flag
+// package sees as the "default" value.
package envflag
import (