cli

package
v0.265.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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
	// 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 New

func New(logger *log.Logger, cfg *config.Config, version string) *CLI

New builds a CLI with the given logger, config and version.

func (*CLI) Client

func (cli *CLI) Client() (*openfga.Client, error)

Client returns a configured OpenFGA client for the resolved configuration.

func (*CLI) ClientWithStore

func (cli *CLI) ClientWithStore() (*openfga.Client, config.Resolved, error)

ClientWithStore returns a client and guarantees a store ID is configured, returning a friendly error otherwise. Most commands need a store.

func (*CLI) GroupRunE

func (*CLI) GroupRunE(cmd *cobra.Command, args []string) error

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) Resolve

func (cli *CLI) Resolve() (config.Resolved, error)

Resolve merges profile, env and flag overrides into a usable configuration.

func (*CLI) RetrySecretCleanup

func (cli *CLI) RetrySecretCleanup() (int, error)

RetrySecretCleanup retries cleanup work durably recorded in the config.

func (*CLI) SaveConfig

func (cli *CLI) SaveConfig() error

SaveConfig persists the config and logs the location at debug level.

func (*CLI) SaveConfigWithSecretCleanup

func (cli *CLI) SaveConfigWithSecretCleanup(profile string, all bool, fields ...string) (bool, error)

SaveConfigWithSecretCleanup persists a profile removal/unset and deletes its keyring entries under the same cross-process config lock.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL