package cli import ( "context" "github.com/urfave/cli/v3" ) // Root builds the full command tree. DefaultCommand launches the TUI when // vault-tui is invoked with no subcommand, matching the plan's "possible // without any subcommand" requirement. func Root(b BuildInfo) *cli.Command { build = b root := &cli.Command{ Name: "vault-tui", Usage: "Terminal UI for HashiCorp Vault", Version: b.Version, DefaultCommand: "ui", // Deliberately no Sources: cli.EnvVars(...) here: internal/config.Resolve // (and config.ResolvePath/SelectProfile for --config/--profile) already // implements the full flag>env>profile>defaults>builtin chain with // correct per-field Origin tracking. Letting urfave/cli additionally // populate these flags from the same env vars would make cmd.IsSet() // indistinguishable between "user passed --address" and "VAULT_ADDR is // set", corrupting both precedence and the status bar's Origin display. Flags: []cli.Flag{ &cli.StringFlag{Name: "config", Usage: "path to config.yaml"}, &cli.StringFlag{Name: "profile", Aliases: []string{"p"}}, &cli.StringFlag{Name: "address"}, &cli.StringFlag{Name: "namespace"}, &cli.StringFlag{Name: "token"}, &cli.StringFlag{Name: "ca-cert"}, &cli.StringFlag{Name: "client-cert"}, &cli.StringFlag{Name: "client-key"}, &cli.BoolFlag{Name: "tls-skip-verify"}, &cli.BoolFlag{Name: "read-only", Usage: "refuse all write operations"}, &cli.BoolFlag{Name: "write", Usage: "allow write operations (overrides a read-only default)"}, &cli.BoolFlag{Name: "no-env", Usage: "ignore VAULT_* environment variables"}, &cli.BoolFlag{Name: "no-color"}, }, Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) { a, err := bootstrap(cmd) if err != nil { return ctx, err } return context.WithValue(ctx, appKey, a), nil }, Commands: []*cli.Command{ uiCommand(), loginCommand(), logoutCommand(), statusCommand(), versionCommand(), listCommand(), readCommand(), writeCommand(), deleteCommand(), configCommand(), }, } return root }