Documentation
¶
Overview ¶
Package cli holds the shared dependencies threaded through every command: the logger, the loaded config, and the global flag overrides. It is the single place commands go to obtain a ready-to-use OpenFGA client.
Index ¶
- func ConsistencyOption(v string) ([]openfga.RequestOption, error)
- func ConsistencyValues() []string
- func ParseTimestamp(flag, value string) (string, error)
- func RegisterConsistencyFlag(cmd *cobra.Command, target *string)
- func RejectFlagAliasConflict(cmd *cobra.Command, primary, alias string) error
- type CLI
- func (cli *CLI) Client() (*openfga.Client, error)
- func (cli *CLI) ClientWithStore() (*openfga.Client, config.Resolved, error)
- func (cli *CLI) CompleteModelIDs(cmd *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective)
- func (*CLI) GroupRunE(cmd *cobra.Command, args []string) error
- func (cli *CLI) Resolve() (config.Resolved, error)
- func (cli *CLI) RetrySecretCleanup() (int, error)
- func (cli *CLI) SaveConfig() error
- func (cli *CLI) SaveConfigWithSecretCleanup(profile string, all bool, fields ...string) (bool, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsistencyOption ¶ added in v0.267.0
func ConsistencyOption(v string) ([]openfga.RequestOption, error)
ConsistencyOption turns a --consistency value into the request option that carries it. An unset flag yields no option, so the client default (HIGHER_CONSISTENCY) applies; an explicit UNSPECIFIED is sent as such, which hands the choice back to the server.
func ConsistencyValues ¶ added in v0.267.0
func ConsistencyValues() []string
ConsistencyValues lists the accepted --consistency values.
func ParseTimestamp ¶ added in v0.267.0
ParseTimestamp validates an RFC 3339 timestamp flag locally, so a value the server would reject (or, worse, quietly misread) is reported as a usage error naming the expected shape. It returns the value unchanged so callers can pass the original string on the wire.
func RegisterConsistencyFlag ¶ added in v0.267.0
RegisterConsistencyFlag adds --consistency to cmd, storing the raw value in target for ConsistencyOption to resolve once the flag has been parsed. It also registers the completion for the flag's closed set of values, so every command that offers --consistency completes it the same way.
func RejectFlagAliasConflict ¶ added in v0.267.0
RejectFlagAliasConflict errors when both an alias and the flag it aliases were set explicitly. The pair writes one variable, so whichever appears last on the command line silently wins — `--max-results 10 --limit 5` reads as a limit of 5 with no complaint. Saying so beats guessing which one was meant.
Types ¶
type CLI ¶
type CLI struct {
Logger *log.Logger
Config *config.Config
Overrides config.Overrides // populated from persistent flags before Execute
// Output is the -o/--output mode (json|yaml|plain|table); it is the
// primary form, with --json/--yaml/--plain kept as aliases that set the
// corresponding toggles directly.
Output string
// JSON toggles machine-readable output across commands.
JSON bool
// YAML toggles machine-readable YAML output across commands.
YAML bool
// Quiet suppresses incidental success/info output.
Quiet bool
// NoInput prevents prompts and the interactive TUI.
NoInput bool
// Plain renders unstyled, tab-separated tables.
Plain bool
// NoColor disables color regardless of terminal/theme.
NoColor bool
// ThemeName, when set via --theme, overrides the configured theme.
ThemeName string
// RequestTimeout bounds each HTTP exchange; zero disables the deadline.
RequestTimeout time.Duration
// TraceWriter receives the --debug request trace. Nil means os.Stderr; it
// exists so tests (and any future --debug-file) can capture the trace
// without touching the process's stderr.
TraceWriter io.Writer
// Runtime secret files provide process-scoped credentials without exposing
// their contents in argv or environment variables.
APITokenFile string
ClientSecretFile string
PrivateKeyFile string
// Version is the build version, injected from main.
Version string
}
CLI is the dependency container shared across commands.
func (*CLI) ClientWithStore ¶
ClientWithStore returns a client and guarantees a store ID is configured, returning a friendly error otherwise. Most commands need a store.
func (*CLI) CompleteModelIDs ¶ added in v0.267.0
func (cli *CLI) CompleteModelIDs(cmd *cobra.Command, args []string, _ string) ([]string, cobra.ShellCompDirective)
CompleteModelIDs suggests authorization model IDs for the resolved store, for a command whose first positional argument is an optional model ID. It lives here so every such command completes the same way instead of each growing its own copy.
func (*CLI) GroupRunE ¶
GroupRunE is the RunE for a command group (a command whose only job is to hold sub-commands). Without it, a group like `ofga stores` is not runnable, so cobra prints help and exits 0 even for a mistyped subcommand like `ofga stores delet` — a typo'd destructive command appears to succeed. As a RunE the group is reached with the stray token as args: no args prints help (the natural `ofga stores` behavior), a stray token is rejected with the same "unknown command … Did you mean" suggestion the root gives.
It is a method on *CLI purely so command constructors can reference it as `cli.GroupRunE` even though their parameter shadows the package name; it uses no receiver state.
func (*CLI) RetrySecretCleanup ¶
RetrySecretCleanup retries cleanup work durably recorded in the config.
func (*CLI) SaveConfig ¶
SaveConfig persists the config and logs the location at debug level.