diff options
| author | Christine Dodrill <me@christine.website> | 2019-06-28 19:31:00 -0400 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-06-28 19:31:00 -0400 |
| commit | cc0db2d9068955f1ff2a68c682cce1c83b2ffd70 (patch) | |
| tree | ea9a2a9ccc257fe48ff15def17e915bd257b094f /internal/internal.go | |
| parent | 81f461f4f8938228fb734f08507858cb4cef4954 (diff) | |
| download | x-cc0db2d9068955f1ff2a68c682cce1c83b2ffd70.tar.xz x-cc0db2d9068955f1ff2a68c682cce1c83b2ffd70.zip | |
internal: add -write-config global flag
Diffstat (limited to 'internal/internal.go')
| -rw-r--r-- | internal/internal.go | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/internal/internal.go b/internal/internal.go index fb236d8..d84b212 100644 --- a/internal/internal.go +++ b/internal/internal.go @@ -5,6 +5,7 @@ import ( "context" "flag" "fmt" + "io/ioutil" "os" "go4.org/legal" @@ -27,6 +28,7 @@ import ( var ( licenseShow = flag.Bool("license", false, "show software licenses?") config = flag.String("config", "", "configuration file, if set (see flagconfyg(4))") + writeConfig = flag.String("write-config", "", "if set, write flags to this file by name/path") manpageGen = flag.Bool("manpage", false, "generate a manpage template?") ) @@ -46,6 +48,16 @@ func HandleStartup() { flagenv.Parse() ctx := opname.With(context.Background(), "internal.HandleStartup") + if val := *writeConfig; val != "" { + ln.Log(ctx, ln.Info("writing flags to file, remember to remove write-config"), ln.F{"fname": val}) + data := flagconfyg.Dump(flag.CommandLine) + err := ioutil.WriteFile(val, data, 0644) + if err != nil { + ln.FatalErr(ctx, err) + } + os.Exit(0) + } + if *config != "" { ln.Log(ctx, ln.Info("loading config"), ln.F{"path": *config}) |
