checkpoint: define top level flag for config dir

This commit is contained in:
Dan Anglin 2024-05-22 16:48:37 +01:00
parent ecc8d51c09
commit 1b76ceb4da
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 14 additions and 3 deletions

View file

@ -15,3 +15,7 @@ func (a *accountNames) Set(value string) error {
return nil
}
type topLevelFlags struct {
configDir string
}

View file

@ -88,6 +88,10 @@ func run() error {
unblock: "unblock a resource (e.g. an account)",
}
globals := topLevelFlags{}
flag.StringVar(&globals.configDir, "config-dir", "", "specify your config directory")
flag.Usage = enbasUsageFunc(summaries)
flag.Parse()
@ -119,7 +123,7 @@ func run() error {
case updateResource:
executor = newUpdateCommand(updateResource, summaries[updateResource])
case whoami:
executor = newWhoAmICommand(whoami, summaries[whoami])
executor = newWhoAmICommand(globals, whoami, summaries[whoami])
case add:
executor = newAddCommand(add, summaries[add])
case remove:

View file

@ -9,11 +9,14 @@ import (
type whoAmICommand struct {
*flag.FlagSet
globals topLevelFlags
}
func newWhoAmICommand(name, summary string) *whoAmICommand {
func newWhoAmICommand(globals topLevelFlags, name, summary string) *whoAmICommand {
command := whoAmICommand{
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
globals: globals,
}
command.Usage = commandUsageFunc(name, summary, command.FlagSet)