backupcmd

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package backupcmd provides the "admin backup" command, which creates a JSONL backup of the entire issue database.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBackupFilename added in v0.1.3

func DefaultBackupFilename(prefix string) string

DefaultBackupFilename returns a timestamped backup filename, optionally including the database prefix. The prefix is sanitized to contain only ASCII letters, preventing path traversal from a corrupt or malicious database prefix.

func NewCmd

func NewCmd(f *cmdutil.Factory) *cli.Command

NewCmd constructs the "admin backup" command, which writes a JSONL backup file into the .np/ directory or a user-specified path.

func Run

func Run(_ context.Context, input RunInput) error

Run executes the backup workflow: determines the output path, creates a gzip-compressed JSONL file, invokes the backup function, and prints the result.

Types

type RunInput

type RunInput struct {
	// DiscoverFunc locates the database file, returning its absolute path.
	// In production this is Factory.DatabasePath (workspace-aware); tests
	// provide a stub. Only called when Output is empty — the discovered
	// .np/ directory determines the default backup location.
	DiscoverFunc func() (string, error)

	// BackupFunc performs the actual backup, writing issue data to the
	// provided writer and returning the number of issues written. In
	// production this wraps svc.Backup; tests provide a stub. The
	// writer is a gzip.Writer that the caller manages — BackupFunc
	// should not close it.
	BackupFunc func(w io.WriteCloser) (int, error)

	// Output is the user-specified destination path. When empty, the
	// backup file is written to the discovered .np/ directory with a
	// timestamp-based filename.
	Output string

	// JSON enables machine-readable JSON output.
	JSON bool

	// WriteTo receives the command's human-readable or JSON output.
	WriteTo io.Writer

	// Prefix is the database's issue ID prefix (e.g., "NP"). When
	// non-empty and the default filename is used (Output is empty or
	// Output is a directory), the prefix is included in the filename:
	// backup-<prefix>.<timestamp>.jsonl.gz.
	Prefix string

	// SuccessIcon returns a colored or plain success indicator for
	// human-readable output. When nil, a default "[ok]" is used.
	SuccessIcon func() string
}

RunInput holds the parameters for the backup command's core logic, decoupled from CLI flag parsing so it can be tested directly.

Jump to

Keyboard shortcuts

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