cli

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package cli handles command-line interface concerns.

Package cli handles command-line interface concerns.

Index

Constants

View Source
const GracefulShutdownTimeout = 3 * time.Second

GracefulShutdownTimeout is the time allowed for graceful shutdown before force exit.

Variables

View Source
var DefaultIdentityRelays = []string{
	"wss://relay.primal.net",
	"wss://relay.damus.io",
	"wss://relay.zapstore.dev",
}

DefaultIdentityRelays are the default relays for identity proof operations.

Functions

func ParseExpiryDuration

func ParseExpiryDuration(s string) (time.Duration, error)

ParseExpiryDuration parses a human-friendly duration string. Supports: y (years), mo (months), d (days), h (hours). Note: Use "mo" for months to avoid conflict with Go's "m" for minutes. Returns the duration or an error if the format is invalid.

func WaitForEnter

func WaitForEnter(ctx context.Context) error

WaitForEnter waits for the user to press Enter, with context support. Returns context.Canceled if the context is cancelled.

func WaitForEnterWithContext

func WaitForEnterWithContext(ctx context.Context) error

WaitForEnterWithContext is an alias for WaitForEnter for backwards compatibility.

Types

type Command

type Command string

Command represents the active subcommand.

const (
	CommandNone     Command = ""
	CommandPublish  Command = "publish"
	CommandIdentity Command = "identity"
	CommandUtils    Command = "utils"
)

type GlobalOptions

type GlobalOptions struct {
	Verbose bool
	NoColor bool
	Version bool
	Help    bool
}

GlobalOptions holds flags available at root level and shared across subcommands.

type IdentityOptions

type IdentityOptions struct {
	LinkKey       string   // Path to certificate file (.p12, .pfx, .pem, .crt)
	LinkKeyExpiry string   // Validity period for identity proof (e.g., "1y", "6mo", "30d")
	Verify        string   // Verify identity proof (path to certificate or APK)
	Relays        []string // Relays for identity proof operations
	Offline       bool     // Output event JSON to stdout instead of publishing
}

IdentityOptions holds flags specific to the identity subcommand.

func (*IdentityOptions) IsInteractive

func (o *IdentityOptions) IsInteractive() bool

IsInteractive returns true if the CLI should be interactive (for identity).

func (*IdentityOptions) ShouldShowSpinners

func (o *IdentityOptions) ShouldShowSpinners() bool

ShouldShowSpinners returns true if spinners/progress should be shown (for identity).

type Options

type Options struct {
	Command Command
	Args    []string // Remaining positional arguments

	Global   GlobalOptions
	Publish  PublishOptions
	Identity IdentityOptions
	Utils    UtilsOptions
}

Options holds all CLI configuration options.

func ParseCommand

func ParseCommand() *Options

ParseCommand parses command-line arguments and returns Options.

type PublishOptions

type PublishOptions struct {
	// Source options
	RepoURL       string
	ReleaseSource string
	Metadata      []string
	Match         string

	// Release-specific options (CLI-only, not in config)
	Commit  string // Git commit hash for reproducible builds
	Channel string // Release channel: main (default), beta, nightly, dev

	// Behavior flags
	Yes                    bool
	Offline                bool // Sign events without uploading/publishing (outputs to stdout)
	Quiet                  bool
	SkipPreview            bool
	OverwriteRelease       bool
	IncludePreReleases     bool
	SkipMetadata           bool
	AppCreatedAtRelease    bool // Use release timestamp for kind 32267 created_at
	SkipAppEvent           bool // Publish only release events (kind 30063/3063), skip kind 32267
	SkipCertificateLinking bool // Skip certificate-to-identity linking check
	Wizard                 bool
	Check                  bool // Verify config fetches arm64-v8a APK (exit 0=success)

	// Server options
	Port int
}

PublishOptions holds flags specific to the publish subcommand.

func (*PublishOptions) IsInteractive

func (o *PublishOptions) IsInteractive() bool

IsInteractive returns true if the CLI should be interactive (for publish).

func (*PublishOptions) ShouldShowSpinners

func (o *PublishOptions) ShouldShowSpinners() bool

ShouldShowSpinners returns true if spinners/progress should be shown (for publish).

func (*PublishOptions) ValidateChannel

func (o *PublishOptions) ValidateChannel() error

ValidateChannel returns an error if the channel is invalid.

type SignalHandler

type SignalHandler struct {
	// contains filtered or unexported fields
}

SignalHandler manages graceful shutdown and signal handling. It provides a context that is cancelled on first Ctrl+C, and forces exit on second Ctrl+C or after the graceful shutdown timeout.

func NewSignalHandler

func NewSignalHandler() *SignalHandler

NewSignalHandler creates a new signal handler with a cancellable context. The handler:

  • First Ctrl+C: cancels context, starts graceful shutdown
  • Second Ctrl+C: forces immediate exit with code 130
  • After GracefulShutdownTimeout: forces exit if still running

func (*SignalHandler) Context

func (h *SignalHandler) Context() context.Context

Context returns the handler's context, which is cancelled on shutdown. Pass this context to all operations that should be cancellable.

func (*SignalHandler) Done

func (h *SignalHandler) Done() <-chan struct{}

Done returns a channel that's closed when shutdown is triggered.

func (*SignalHandler) IsShuttingDown

func (h *SignalHandler) IsShuttingDown() bool

IsShuttingDown returns true if shutdown has been triggered.

func (*SignalHandler) OnCleanup

func (h *SignalHandler) OnCleanup(fn func())

OnCleanup registers a function to be called during graceful shutdown. Cleanup functions are called in reverse order of registration (LIFO).

func (*SignalHandler) Shutdown

func (h *SignalHandler) Shutdown()

Shutdown triggers a graceful shutdown programmatically.

func (*SignalHandler) Stop

func (h *SignalHandler) Stop()

Stop releases resources and stops watching for signals. Call this in a defer after NewSignalHandler.

type UtilsOptions added in v0.4.0

type UtilsOptions struct {
	Operation string // "extract-apk" or "check-releases"
}

UtilsOptions holds flags specific to the utils subcommand.

Jump to

Keyboard shortcuts

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