diffargs

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package diffargs provides shared diff command argument parsing logic for SSM Parameter Store and Secrets Manager.

The diff command compares two versions of a parameter (SSM Parameter Store) or secret (Secrets Manager). This package provides a generic ParseArgs function that handles the various argument patterns supported by both services.

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 param diff /app/config#3 suve secret diff my-secret:AWSPREVIOUS

  • 2 args: Compare two fully-specified versions suve param diff /app/config#1 /app/config#2 suve 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 param diff /app/config '#3' suve secret diff my-secret ':AWSPREVIOUS'

  • 3 args: Name + two specifiers suve param diff /app/config '#1' '#2' suve 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 param diff /app/config#1 '#2' suve secret diff my-secret:AWSPREVIOUS ':AWSCURRENT'

Return Value Semantics

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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseArgs

func ParseArgs[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)

ParseArgs parses diff command arguments into two version specifications.

This function is generic over the absolute specifier type A, which differs between SSM Parameter Store (AbsoluteSpec with Version *int64) and Secrets Manager (AbsoluteSpec with ID *string and Label *string).

Parameters

  • args: Command line arguments (1-3 arguments supported)
  • parse: Service-specific parser function (e.g., paramversion.Parse, secretversion.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. For SSM Parameter Store: func(abs) bool { return abs.Version != nil } For Secrets Manager: func(abs) bool { return abs.ID != nil || abs.Label != nil }
  • prefixes: Characters that start a specifier (e.g., "#~" for SSM Parameter Store, "#:~" for Secrets Manager). 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 := ParseArgs(
    args,
    paramversion.Parse,
    func(abs paramversion.AbsoluteSpec) bool { return abs.Version != nil },
    "#~",
    "usage: suve param diff <spec1> [spec2] | <name> <version1> [version2]",
)

Secrets Manager usage:

spec1, spec2, err := ParseArgs(
    args,
    secretversion.Parse,
    func(abs secretversion.AbsoluteSpec) bool { return abs.ID != nil || abs.Label != nil },
    "#:~",
    "usage: suve secret diff <spec1> [spec2] | <name> <version1> [version2]",
)

Types

This section is empty.

Jump to

Keyboard shortcuts

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