diff options
| author | Mitchell Riedstra <mitch@riedstra.dev> | 2025-05-03 09:53:52 -0400 |
|---|---|---|
| committer | Mitchell Riedstra <mitch@riedstra.dev> | 2025-05-03 09:53:52 -0400 |
| commit | 7dc357b940a44db7028940c106564de5408da42f (patch) | |
| tree | 5518f8e2e80778605833ccde3ee2fa1410dd30a6 | |
| parent | c9047cfbc62191ccbe47c2ca0896eb4b192a7223 (diff) | |
| download | envflag-7dc357b940a44db7028940c106564de5408da42f.tar.gz envflag-7dc357b940a44db7028940c106564de5408da42f.tar.xz | |
| -rw-r--r-- | LICENSE | 13 | ||||
| -rw-r--r-- | main.go | 29 |
2 files changed, 42 insertions, 0 deletions
@@ -0,0 +1,13 @@ +Copyright 2025 Mitchell Riedstra + +Permission to use, copy, modify, and/or distribute this software for any purpose +with or without fee is hereby granted, provided that the above copyright notice +and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER +TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF +THIS SOFTWARE. @@ -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 ( |
