Skip to content

Commit

Permalink
help output (#105)
Browse files Browse the repository at this point in the history
* help output
* do not expand sub-tasks
  • Loading branch information
gertd authored Jan 5, 2023
1 parent 9555853 commit 148f38b
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions cmd/policy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
"github.com/pkg/errors"
)

const (
appName string = "policy"
)

var tmpConfig *config.Config

func ConfigExpander() kong.Resolver {
Expand Down Expand Up @@ -110,7 +114,7 @@ var PolicyCLI struct {
Repl ReplCmd `cmd:"" help:"Sets you up with a shell for running queries using an OPA instance with a policy loaded."`
Remote RemoteCmd `cmd:"" help:"Extra commands for managing policy images on a remote registry."`
Init InitCmd `cmd:"" help:"(Deprecated) Initialize policy repo"`
Templates TemplatesCmd `cmd:"" help:""`
Templates TemplatesCmd `cmd:"" help:"List and apply templates"`
Version VersionCmd `cmd:"" help:"Prints version information."`
}

Expand Down Expand Up @@ -151,22 +155,36 @@ func main() {
panic(errors.Wrap(err, "failed to determine user home directory"))
}

ctx := kong.Parse(&PolicyCLI, kong.Resolvers(ConfigExpander()), kong.Vars{"userHome": home})
ctx := kong.Parse(
&PolicyCLI,
kong.Name(appName),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
NoAppSummary: false,
Summary: false,
Compact: true,
Tree: false,
FlagsLast: true,
Indenter: kong.SpaceIndenter,
NoExpandSubcommands: true,
}),
kong.Resolvers(ConfigExpander()), kong.Vars{"userHome": home},
)

g = &Globals{
Debug: PolicyCLI.Debug,
Config: PolicyCLI.Config,
Verbosity: PolicyCLI.Verbosity,
Insecure: PolicyCLI.Insecure,
}
cleanup := g.setup()

err = ctx.Run(g)
cleanup := g.setup()

if err != nil {
if err = ctx.Run(g); err != nil {
g.App.UI.Problem().Msg(err.Error())
cleanup()
os.Exit(1)
}

cleanup()
}

0 comments on commit 148f38b

Please sign in to comment.