feat: simplify flag parsing in config plugin

Commands should be written such that they take arguments as is.
This commit is contained in:
Jose Diaz-Gonzalez
2020-05-29 01:18:47 -04:00
parent c22f78c913
commit a93cec63be
6 changed files with 225 additions and 166 deletions

View File

@@ -21,11 +21,12 @@ Additional commands:`
helpContent = `
config (<app>|--global), Pretty-print an app or global environment
config:bundle (<app>|--global) [--merged], Bundle environment into tarfile
config:clear (<app>|--global), Clears environment variables
config:export (<app>|--global) [--envfile], Export a global or app environment
config:get (<app>|--global) KEY, Display a global or app-specific config value
config:keys (<app>|--global) [--merged], Show keys set in environment
config:bundle [--merged] (<app>|--global), Bundle environment into tarfile
config:clear [--no-restart] (<app>|--global), Clears environment variables
config:export [--format=FORMAT] [--merged] (<app>|--global), Export a global or app environment
config:get [--quoted] (<app>|--global) KEY, Display a global or app-specific config value
config:keys [--merged] (<app>|--global), Show keys set in environment
config:show [--merged] (<app>|--global), Show keys set in environment
config:set [--encoded] [--no-restart] (<app>|--global) KEY1=VALUE1 [KEY2=VALUE2 ...], Set one or more config vars
config:unset [--no-restart] (<app>|--global) KEY1 [KEY2 ...], Unset one or more config vars
`
@@ -37,14 +38,19 @@ func main() {
cmd := flag.Arg(0)
switch cmd {
case "config", "config:show":
case "config":
common.LogWarn("Deprecated: Use the 'config:show' command instead")
args := flag.NewFlagSet("config:show", flag.ExitOnError)
global := args.Bool("global", false, "--global: use the global environment")
shell := args.Bool("shell", false, "--shell: in a single-line for usage in command-line utilities [deprecated]")
export := args.Bool("export", false, "--export: print the env as eval-compatible exports [deprecated]")
merged := args.Bool("merged", false, "--merged: display the app's environment merged with the global environment")
args.Parse(os.Args[2:])
config.CommandShow(args.Args(), *global, *shell, *export, *merged)
appName := args.Arg(0)
err := config.CommandShow(appName, *global, *merged, *shell, *export)
if err != nil {
common.LogFail(err.Error())
}
case "config:help":
usage()
case "help":