Documentation
¶
Overview ¶
Package generic provides the provider-neutral command scaffolding shared by every provider: show, log, diff, list, tag and untag. Each file owns one command's flow (flags, validation, pager gating, output dispatch) and takes the provider-specific parts through a small per-command config and presenter, so a provider's CLI package only supplies help text, its version grammar and its renderers.
Index ¶
- func DiffCommand[S any](cfg DiffConfig[S]) *cli.Command
- func ListCommand(cfg ListConfig) *cli.Command
- func LogCommand(cfg LogConfig) *cli.Command
- func LogPatchParent(i, n int, reverse bool) (parentIdx int, oldest bool)
- func ParseDiffArgs[A any](args []string, parse func(string) (*version.Spec[A], error), ...) (*version.Spec[A], *version.Spec[A], error)
- func ShowCommand[S any](cfg ShowConfig[S]) *cli.Command
- func TagCommand(cfg TagConfig) *cli.Command
- func UntagCommand(cfg TagConfig) *cli.Command
- type DiffConfig
- type DiffOptions
- type DiffPresenter
- type DiffRunner
- type ListConfig
- type ListEntry
- type ListJSONOutputItem
- type ListOptions
- type ListRunner
- type LogConfig
- type LogOptions
- type LogPresenter
- type LogRequest
- type LogRunner
- type ShowConfig
- type ShowOptions
- type ShowPresenter
- type ShowRunner
- type TagConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DiffCommand ¶
func DiffCommand[S any](cfg DiffConfig[S]) *cli.Command
DiffCommand returns the generic diff command wired with the provider DiffConfig.
func ListCommand ¶
func ListCommand(cfg ListConfig) *cli.Command
ListCommand returns the generic list command wired with the provider ListConfig.
func LogCommand ¶
LogCommand returns the generic log command wired with the provider LogConfig.
func LogPatchParent ¶
LogPatchParent computes, for version i in a fetched window of n versions, the index of its parent (the immediately-older version) and whether i is the oldest version in the window.
git log -p attaches each version's own creation patch under its own header — the diff from its parent to itself. In newest-first order the parent is the next entry (i+1); in reverse (oldest-first) order it is the previous entry (i-1). The oldest version in the window has no parent in the list; the caller renders it as an all-added creation diff, but only when it is genuinely the initial version (guarding against a --number / date-filter window cut).
func ParseDiffArgs ¶
func ParseDiffArgs[A any]( args []string, parse func(string) (*version.Spec[A], error), hasAbsolute func(A) bool, prefixes string, usage string, ) (*version.Spec[A], *version.Spec[A], error)
ParseDiffArgs parses diff command arguments into two version specifications. Every versioned diff command (AWS, Google Cloud, Azure Key Vault) wraps it with its grammar from internal/version and its usage string.
The diff command compares two versions of one parameter or secret. The examples below use AWS specs (Parameter Store "#N", Secrets Manager labels). ParseDiffArgs handles the argument patterns every provider supports.
Argument Patterns ¶
The diff command supports three formats for specifying versions to compare:
## Full Spec Format
Each argument is a complete specification including name and version.
1 arg: Compare specified version against default (latest/AWSCURRENT) suve aws param diff /app/config#3 suve aws secret diff my-secret:AWSPREVIOUS
2 args: Compare two fully-specified versions suve aws param diff /app/config#1 /app/config#2 suve aws secret diff my-secret:AWSPREVIOUS my-secret:AWSCURRENT
## Partial Spec Format
Name is specified separately from version specifiers.
2 args: Name + specifier → compare with default suve aws param diff /app/config '#3' suve aws secret diff my-secret ':AWSPREVIOUS'
3 args: Name + two specifiers suve aws param diff /app/config '#1' '#2' suve aws secret diff my-secret ':AWSPREVIOUS' ':AWSCURRENT'
## Mixed Format
First argument is full spec, second is specifier-only (inherits name from first).
- 2 args: Full spec + specifier suve aws param diff /app/config#1 '#2' suve aws secret diff my-secret:AWSPREVIOUS ':AWSCURRENT'
Return Value Semantics ¶
ParseDiffArgs always returns (spec1, spec2) where the comparison is performed as:
diff(spec1, spec2) = "what changed from spec1 to spec2"
This means spec1 is the "old" version and spec2 is the "new" version. The diff output will show:
- Lines removed from spec1 as "-" (red)
- Lines added in spec2 as "+" (green)
This function is generic over the absolute specifier type A, which each grammar in internal/version defines (version.NumericAbsolute, version.OpaqueAbsolute).
Parameters ¶
- args: Command line arguments (1-3 arguments supported)
- parse: Service-specific parser function (e.g., version.AWSParameterStore.Parse, version.AWSSecretsManager.Parse)
- hasAbsolute: Returns true if the absolute specifier is set (non-zero). Used to distinguish "mixed" pattern from "partial spec" pattern in 2-arg case. Pass the grammar's IsSet (version.NumericAbsolute.IsSet, version.OpaqueAbsolute.IsSet).
- prefixes: Characters that start a specifier ("#~" for a numeric grammar, "#:~" for an opaque grammar with labels). Used to detect if second argument is specifier-only.
- usage: Error message to show when argument count is invalid.
Return Values ¶
Returns (spec1, spec2, nil) on success, where:
- spec1: The "from" version (shown with "-" in diff)
- spec2: The "to" version (shown with "+" in diff)
Returns (nil, nil, error) on parse failure or invalid argument count.
Examples ¶
SSM Parameter Store usage:
spec1, spec2, err := ParseDiffArgs(
args,
version.AWSParameterStore.Parse,
version.NumericAbsolute.IsSet,
"#~",
"usage: suve aws param diff <spec1> [spec2] | <name> #<version1> [#<version2>]",
)
Secrets Manager usage:
spec1, spec2, err := ParseDiffArgs(
args,
version.AWSSecretsManager.Parse,
version.OpaqueAbsolute.IsSet,
"#:~",
"usage: suve aws secret diff <spec1> [spec2] | <name> #<version1> [#<version2>]",
)
func ShowCommand ¶
func ShowCommand[S any](cfg ShowConfig[S]) *cli.Command
ShowCommand returns the generic show command wired with the provider ShowConfig.
func TagCommand ¶
TagCommand returns the generic tag command wired with the provider TagConfig.
func UntagCommand ¶
UntagCommand returns the generic untag command wired with the provider TagConfig.
Types ¶
type DiffConfig ¶
type DiffConfig[S any] struct { // Usage is the one-line command usage string. Usage string // ArgsUsage is the positional-arguments usage string. ArgsUsage string // Description is the long help text. Description string // ParseDiffArgs parses the raw positional args into two version specs. ParseDiffArgs func(args []string) (S, S, error) // NewPresenter builds the provider DiffPresenter bound to the two specs. NewPresenter func(ctx context.Context, spec1, spec2 S) (DiffPresenter, error) }
DiffConfig holds the provider-specific configuration for the diff command.
type DiffOptions ¶
type DiffOptions struct {
//declscope:ignore overexported // diff_test.go runs the diff with the AWS presenters, which import this package
ParseJSON bool
Output output.Format
// contains filtered or unexported fields
}
DiffOptions holds the shared diff options.
type DiffPresenter ¶
type DiffPresenter interface {
// Fetch resolves both specs and loads their entries via the provider usecase.
Fetch(ctx context.Context) error
// OldValue and NewValue return the two raw values to be compared.
OldValue() string
NewValue() string
// Labels returns the unified-diff header labels for the old and new sides.
Labels() (oldLabel, newLabel string)
// RenderJSON writes the provider JSON output. diff is the pre-computed raw
// unified diff (empty when the versions are identical).
RenderJSON(stdout io.Writer, oldValue, newValue string, identical bool, diff string) error
// Hints writes the provider-specific hints shown when versions are identical.
Hints(stderr io.Writer)
}
DiffPresenter renders a diff for a specific provider. Implementations are stateful: Fetch loads both versions, and the subsequent methods render them.
type DiffRunner ¶
type DiffRunner struct {
Presenter DiffPresenter
Options DiffOptions
Stdout io.Writer
Stderr io.Writer
}
DiffRunner executes the diff command over a provider DiffPresenter.
type ListConfig ¶
type ListConfig struct {
// Usage is the one-line command usage string.
Usage string
// ArgsUsage is the positional-arguments usage string.
ArgsUsage string
// Description is the long help text.
Description string
// Flags is the provider's flag set (param adds --recursive; secret does not).
Flags []cli.Flag
// NewList builds the entry-producing closure from the CLI context. withValue
// mirrors the shared --show flag so the provider can request values.
NewList func(ctx context.Context, cmd *cli.Command, withValue bool) (func(context.Context) ([]ListEntry, error), error)
}
ListConfig holds the provider-specific configuration for the list command.
type ListJSONOutputItem ¶
type ListJSONOutputItem struct {
Name string `json:"name"`
Value *string `json:"value,omitempty"` // nil when error or not requested, pointer to distinguish from empty string
Error string `json:"error,omitempty"`
}
ListJSONOutputItem represents a single item in JSON output.
type ListOptions ¶
ListOptions holds the shared list options.
type ListRunner ¶
type ListRunner struct {
List func(ctx context.Context) ([]ListEntry, error)
Options ListOptions
Stdout io.Writer
Stderr io.Writer
}
ListRunner executes the list command over a provider-supplied entry source.
type LogConfig ¶
type LogConfig struct {
// Usage is the one-line command usage string.
Usage string
// ArgsUsage is the positional-arguments usage string.
ArgsUsage string
// Description is the long help text.
Description string
// UsageError is returned when the resource name argument is missing.
UsageError string
// Flags is the provider's flag set (param adds --max-value-length; the
// --number/--since/--until usage strings differ between providers).
Flags []cli.Flag
// NewPresenter builds the provider LogPresenter bound to the fetch request.
NewPresenter func(ctx context.Context, req LogRequest) (LogPresenter, error)
}
LogConfig holds the provider-specific configuration for the log command.
type LogOptions ¶
type LogOptions struct {
//declscope:ignore overexported // log_test.go runs the log with the AWS presenters, which import this package
ShowPatch bool
//declscope:ignore overexported // log_test.go runs the log with the AWS presenters, which import this package
ParseJSON bool
//declscope:ignore overexported // log_test.go runs the log with the AWS presenters, which import this package
Reverse bool
Oneline bool
Output output.Format
//declscope:ignore overexported // log_test.go runs the log with the AWS presenters, which import this package
MaxValueLength int
// contains filtered or unexported fields
}
LogOptions holds the shared render options.
type LogPresenter ¶
type LogPresenter interface {
// Fetch loads the version history via the provider usecase.
Fetch(ctx context.Context) error
// Len returns the number of versions loaded.
Len() int
// RenderJSON writes the provider-specific JSON array for all versions.
RenderJSON(stdout io.Writer) error
// RenderOneline writes the compact one-line form for version i.
RenderOneline(stdout io.Writer, i, maxValueLength int)
// RenderHeader writes the "Version ..." line and Date line for version i.
RenderHeader(stdout io.Writer, i int)
// RenderValue writes the value preview for version i (default, non-patch mode).
// Providers without a default value preview (e.g. secrets) make this a no-op.
RenderValue(stdout io.Writer, i, maxValueLength int)
// RenderPatch writes the diff between version i and its neighbor (patch mode).
RenderPatch(stdout, stderr io.Writer, i int, parseJSON, reverse bool)
}
LogPresenter renders version history for a specific provider. Implementations are stateful: Fetch loads the history, and the render methods format each version.
type LogRequest ¶
type LogRequest struct {
Name string
MaxResults int32
Since *time.Time
Until *time.Time
Reverse bool
}
LogRequest holds the version-history fetch parameters (passed to the usecase).
type LogRunner ¶
type LogRunner struct {
Presenter LogPresenter
Options LogOptions
Stdout io.Writer
Stderr io.Writer
}
LogRunner executes the log command over a provider LogPresenter.
type ShowConfig ¶
type ShowConfig[S any] struct { // Usage is the one-line command usage string. Usage string // ArgsUsage is the positional-arguments usage string. ArgsUsage string // Description is the long help text. Description string // UsageError is returned when the resource name argument is missing. UsageError string // ParseSpec parses the raw name argument into the provider's version spec. ParseSpec func(arg string) (S, error) // NewPresenter builds the provider ShowPresenter bound to the parsed spec (this // is where the provider constructs its client and use case). NewPresenter func(ctx context.Context, spec S) (ShowPresenter, error) }
ShowConfig holds the provider-specific configuration for the show command.
type ShowOptions ¶
type ShowOptions struct {
ParseJSON bool
Raw bool
Output output.Format
// contains filtered or unexported fields
}
ShowOptions holds the shared show options.
type ShowPresenter ¶
type ShowPresenter interface {
// Fetch resolves the version spec and loads the entry via the provider usecase.
Fetch(ctx context.Context) error
// Value returns the display value. When parseJSON is set it applies the
// provider's parse-json rules (which may warn to stderr) and records internal
// state used by the render methods.
Value(parseJSON bool, stderr io.Writer) string
// RenderText writes the metadata block followed by the value.
RenderText(stdout io.Writer, value string)
// RenderJSON writes the provider-specific JSON output.
RenderJSON(stdout io.Writer, value string) error
}
ShowPresenter renders a single show result for a specific provider. Implementations are stateful: Fetch loads the entry, and the subsequent methods render it.
type ShowRunner ¶
type ShowRunner struct {
Presenter ShowPresenter
Options ShowOptions
Stdout io.Writer
Stderr io.Writer
}
ShowRunner executes the show command over a provider ShowPresenter.
type TagConfig ¶
type TagConfig struct {
// Usage is the one-line command usage string.
Usage string
// ArgsUsage is the positional-arguments usage string.
ArgsUsage string
// Description is the long help text.
Description string
// Noun is the resource word used in success messages ("parameter"/"secret").
Noun string
// UsageError is the error returned when required arguments are missing.
UsageError string
// NewTagger builds the provider's Tagger from the CLI context.
NewTagger func(ctx context.Context) (provider.Tagger, error)
}
TagConfig holds the provider-specific configuration for the tag/untag commands.