cmd

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 41 Imported by: 0

Documentation

Overview

Package cmd implements the dotdrift command-line interface and its subcommands.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(version string, args []string) error

Run executes the CLI with the given version.

Types

type ApplyCmd

type ApplyCmd struct {
	Profile string    `help:"Path to profile directory" type:"existingdir" default:"."`
	State   string    `help:"Path to state file" type:"path" default:""`
	Yes     bool      `help:"Answer yes to mise prompts" default:"false"`
	Verbose bool      `` /* 139-byte string literal not displayed */
	Diff    string    `` /* 130-byte string literal not displayed */
	Backup  bool      `` /* 193-byte string literal not displayed */
	Modules []string  `arg:"" optional:"" name:"modules" help:"Limit scope to these modules (space or comma separated)"`
	Out     io.Writer `kong:"-"`

	// Section flags: positives select exactly those sections, negatives
	// (--no-<section>) subtract, no flags runs everything. Each maps to
	// the same-named module.toml plan section. No default:"false" tag —
	// an explicit default marks the flag Set in kong, which would defeat
	// presence detection (positive vs negated vs absent). The group tag
	// renders all six under one "Section flags" heading in --help.
	Packages bool `group:"Section flags" help:"Apply only the packages section" negatable:""`
	Tools    bool `group:"Section flags" help:"Apply only the tools section" negatable:""`
	Dotfiles bool `group:"Section flags" help:"Apply only the dotfiles section (user + system)" negatable:""`
	Mounts   bool `group:"Section flags" help:"Apply only the mounts section (units + services + destination dirs)" negatable:""`
	Smb      bool `group:"Section flags" help:"Apply only the smb section" negatable:""`
	Hooks    bool `group:"Section flags" help:"Run pre/post hook commands" negatable:""`
	// contains filtered or unexported fields
}

ApplyCmd runs the full pipeline and always resumes.

func (*ApplyCmd) AfterApply added in v0.23.0

func (c *ApplyCmd) AfterApply(kctx *kong.Context) error

AfterApply captures the parse context so Run can read which section flags were explicitly set (positive or negated) — a plain bool field cannot distinguish `--hooks` from an untouched default.

func (*ApplyCmd) Run

func (c *ApplyCmd) Run() error

Run executes the apply pipeline with resume semantics.

type CLI

type CLI struct {
	RootFlags `kong:"embed"`

	Init     InitCmd     `cmd:"" help:"Create or clone a profile"`
	Detect   DetectCmd   `cmd:"" help:"Detect system facts"`
	Modules  ModulesCmd  `cmd:"" help:"List selected and skipped modules"`
	Plan     PlanCmd     `cmd:"" help:"Print the effective plan"`
	Apply    ApplyCmd    `cmd:"" help:"Apply the profile"`
	Status   StatusCmd   `cmd:"" help:"Show status"`
	Onboard  OnboardCmd  `cmd:"" help:"Onboard paths into a module" aliases:"add,adopt"`
	Restore  RestoreCmd  `cmd:"" help:"Restore copy-mode targets from module backups"`
	Generate GenerateCmd `cmd:"" help:"Generate mounts/smb modules"`
	Paru     ParuCmd     `cmd:"" help:"paru mise plugin backend (internal)"`
	Version  VersionCmd  `cmd:"" help:"Show version information"`
	// contains filtered or unexported fields
}

CLI is the root command structure for dotdrift.

func (*CLI) AfterApply

func (cli *CLI) AfterApply(kctx *kong.Context) error

AfterApply is called after Kong parses the CLI but before the command runs.

type DetectCmd

type DetectCmd struct {
	Out io.Writer `kong:"-"`
	// OSReader and GPUReader allow tests to inject fakes. When nil, real system
	// readers are used.
	OSReader  detect.OSReleaseReader `kong:"-"`
	GPUReader detect.GPUReader       `kong:"-"`
}

DetectCmd prints system facts.

func (*DetectCmd) Run

func (c *DetectCmd) Run() error

Run gathers and prints system facts in a stable line-oriented format.

type GenerateCmd added in v0.2.0

type GenerateCmd struct {
	Mounts GenerateMountsCmd `cmd:"" help:"Generate a mounts module (systemd units)"`
	Smb    GenerateSmbCmd    `cmd:"" help:"Generate an smb module (samba shares)"`
}

GenerateCmd groups the module generators.

type GenerateMountsCmd added in v0.2.0

type GenerateMountsCmd struct {
	Profile     string    `help:"Path to profile directory" type:"existingdir" default:"."`
	Layer       string    `help:"Target layer" enum:"base,host,user" default:"base"`
	Module      string    `help:"Module id" default:"mounts"`
	Hostname    string    `help:"Hostname for --layer host (default: detected)"`
	Username    string    `help:"Username for --layer user (default: detected)"`
	Name        string    `help:"Mount name (input flag)"`
	Source      string    `help:"Mount source, e.g. UUID=<uuid> or server:/export (input flag)"`
	Destination string    `help:"Mount destination path (input flag)"`
	Type        string    `help:"Filesystem type; the registry preset applies when --option is omitted (input flag)"`
	Option      []string  `help:"Mount option (repeatable; overrides the registry preset for --type)"`
	StartAt     string    `name:"startat" help:"OnCalendar expression; adds a .timer/.service pair (input flag)"`
	State       string    `help:"Mount state: enabled or disabled (default enabled)"`
	ListVolumes bool      `name:"list-volumes" help:"Print detected volumes and exit"`
	TUI         *bool     `negatable:"" help:"Force the interactive wizard (--no-tui forces CLI mode)"`
	Out         io.Writer `kong:"-"`
}

GenerateMountsCmd generates a mounts module: systemd .mount units (plus .service/.timer pairs for --startat) and the module.toml scope, [mounts] section, packages, and dotfile entries that place them.

func (*GenerateMountsCmd) Run added in v0.2.0

func (c *GenerateMountsCmd) Run() error

Run implements the mounts generator: mode selection, then either the volume table, the wizard, or CLI-mode assembly + WriteModule.

type GenerateSmbCmd added in v0.2.0

type GenerateSmbCmd struct {
	Profile  string    `help:"Path to profile directory" type:"existingdir" default:"."`
	Layer    string    `help:"Target layer" enum:"base,host,user" default:"base"`
	Module   string    `help:"Module id" default:"smb"`
	Hostname string    `help:"Hostname for --layer host (default: detected)"`
	Username string    `help:"Username for --layer user (default: detected)"`
	Group    string    `help:"Samba group (default \"smb\"; input flag)"`
	Users    []string  `name:"user" help:"Samba user (repeatable; default: the invoking user)"`
	Avahi    *bool     `negatable:"" help:"Avahi service discovery (default on; --no-avahi records an explicit off)"`
	Shares   []string  `name:"share" help:"Share as name=path (repeatable; at least one required in CLI mode)"`
	Writable *bool     `negatable:"" help:"Shares writable (default on; input flag)"`
	Readonly bool      `help:"Shares read-only: sets writable=false"`
	Public   bool      `help:"Shares public (guest access; input flag)"`
	TUI      *bool     `negatable:"" help:"Force the interactive wizard (--no-tui forces CLI mode)"`
	Out      io.Writer `kong:"-"`
}

GenerateSmbCmd generates an smb module: shares.conf, a one-time smb.conf seed, and the module.toml scope, smb section, packages, and dotfile entries that place them.

func (*GenerateSmbCmd) Run added in v0.2.0

func (c *GenerateSmbCmd) Run() error

Run implements the smb generator.

type InitCmd

type InitCmd struct {
	Path string `arg:"" help:"Local path or git URL for the profile" default:"."`
}

InitCmd creates or clones a profile.

func (*InitCmd) Run

func (c *InitCmd) Run() error

Run creates a new profile directory or clones a git URL.

type ModulesCmd

type ModulesCmd struct {
	Profile string    `help:"Path to profile directory" type:"existingdir" default:"."`
	Modules []string  `arg:"" optional:"" name:"modules" help:"Limit scope to these modules (space or comma separated)"`
	Out     io.Writer `kong:"-"`
}

ModulesCmd lists selected and skipped modules for a profile.

func (*ModulesCmd) Run

func (c *ModulesCmd) Run() error

Run loads the profile and prints selection status.

type OnboardCmd

type OnboardCmd struct {
	Paths []string `arg:"" optional:"" help:"Paths to onboard into the module"`

	Profile  string      `help:"Path to profile directory" type:"existingdir" default:"."`
	App      string      `help:"Module directory name (inferred from the first path when omitted)"`
	Mode     string      `help:"Dotfile mode" enum:"symlink,symlink-each,copy,template" default:"symlink"`
	Packages []string    `help:"Distro packages to declare; each entry is a bare name or name=\"description\" (the description becomes a TOML comment)"`
	Tools    []string    `help:"Mise tools to declare"`
	Host     overlayFlag `help:"Onboard into hosts/<hostname>; no value = current host, --host=<name> = explicit, flag omitted = base layer"`
	User     overlayFlag `help:"Onboard into users/<username>; no value = current user, --user=<name> = explicit, flag omitted = base layer"`
	DryRun   bool        `help:"Preview only"`
	Yes      bool        `help:"Answer yes to mise prompts" default:"false"`
	Verbose  bool        `` /* 139-byte string literal not displayed */
	// Mise injects a runner for tests; nil uses the real mise bootstrap.
	Mise mise.Runner `kong:"-"`
}

OnboardCmd copies live paths into a module and applies them.

func (*OnboardCmd) Run

func (c *OnboardCmd) Run() error

Run implements the onboard command.

type ParuCmd added in v0.10.0

type ParuCmd struct {
	Installed ParuInstalledCmd `cmd:"" help:"Check package install status (plugin backend)"`
	Install   ParuInstallCmd   `cmd:"" help:"Install packages via paru (plugin backend)"`
}

ParuCmd is the dotdrift mise package-plugin backend for the `paru` manager. These subcommands are invoked by the Lua plugin shim, not by end users directly. They are thin wrappers over internal/paru.

type ParuInstallCmd added in v0.10.0

type ParuInstallCmd struct {
	Names  []string `arg:"" optional:"" help:"Package names to install"`
	DryRun bool     `name:"dry-run" help:"Print what would happen without running"`
	Update bool     `help:"Refresh package manager metadata first"`
}

ParuInstallCmd installs packages via paru -S --needed --noconfirm.

func (*ParuInstallCmd) Run added in v0.10.0

func (c *ParuInstallCmd) Run() error

type ParuInstalledCmd added in v0.10.0

type ParuInstalledCmd struct {
	Names []string `arg:"" optional:"" help:"Package names to check"`
}

ParuInstalledCmd checks package status via pacman -Q and emits the line protocol consumed by the Lua plugin shim.

func (*ParuInstalledCmd) Run added in v0.10.0

func (c *ParuInstalledCmd) Run() error

type PlanCmd

type PlanCmd struct {
	Profile   string       `help:"Path to profile directory" type:"existingdir" default:"."`
	JSON      bool         `short:"j" help:"Print the plan as a single JSON object (suppresses the text rendering and warnings)"`
	Deps      bool         `help:"Show dependency tree for packages in the install list"`
	DepsDepth int          `default:"1" help:"Dependency recursion depth (requires --deps)"`
	Modules   []string     `arg:"" optional:"" name:"modules" help:"Limit scope to these modules (space or comma separated)"`
	Facts     *facts.Facts `kong:"-"`
	Out       io.Writer    `kong:"-"`
}

PlanCmd prints the resolved plan without side effects.

func (*PlanCmd) Run

func (c *PlanCmd) Run() error

Run loads the profile and prints the resolved plan.

type RestoreCmd added in v0.26.0

type RestoreCmd struct {
	Targets []string  `arg:"" optional:"" name:"targets" help:"Live target paths to restore (absolute or ~/), as they were when backed up"`
	Profile string    `help:"Path to profile directory" type:"existingdir" default:"."`
	Gen     string    `` /* 126-byte string literal not displayed */
	DryRun  bool      `help:"List what would be restored without touching anything"`
	List    bool      `help:"List backup generations (per module, or the generations holding the given targets) and exit"`
	Out     io.Writer `kong:"-"`
}

RestoreCmd copies backed-up copy-mode destinations back to their live targets (the inverse of apply --backup).

func (*RestoreCmd) Run added in v0.26.0

func (c *RestoreCmd) Run() error

Run implements the restore command.

type RootFlags

type RootFlags struct {
	LogLevel      string `help:"Log level (trace,debug,info,warn,error)" enum:"trace,debug,info,warn,error" default:"info" env:"LOG_LEVEL"`
	LogFormat     string `help:"Log format (console,json)" enum:"console,json" default:"console" env:"LOG_FORMAT"`
	PProf         bool   `help:"Enable pprof profiling server" default:"false"`
	PProfListenOn string `help:"Listen address for pprof profiling server" default:"127.0.0.1:6060"`
	NoColor       bool   `help:"Disable colored output" default:"false" env:"NO_COLOR"`
}

RootFlags holds global CLI flags.

type StatusCmd

type StatusCmd struct {
	Profile string   `help:"Path to profile directory" type:"existingdir" default:"."`
	State   string   `help:"Path to state file" type:"path" default:""`
	Verbose bool     `help:"Show each probe as it starts ('checking <section>: <item>') on stderr" short:"v" default:"false"`
	Jobs    int      `help:"Concurrent probe workers (0 = number of CPUs)" short:"j" default:"0"`
	Diff    string   `help:"Show diff for files whose content differs; bare = internal diff, --diff=tool uses the named tool" default:""`
	Modules []string `arg:"" optional:"" name:"modules" help:"Limit scope to these modules (space or comma separated)"`
	// contains filtered or unexported fields
}

StatusCmd reports drift between the resolved profile and the live system, plus the apply resume cursor. Read-only; exits 0 even when drift is found.

func (*StatusCmd) Run

func (c *StatusCmd) Run() error

Run loads state, resolves the plan, probes the live system for drift, and prints the report. Only real errors (detect/load/resolve/corrupt state) return non-nil; drift is reported, never an error.

type VersionCmd

type VersionCmd struct{}

VersionCmd shows version information

func (*VersionCmd) Run

func (v *VersionCmd) Run(version string) error

Run prints the application name and version.

Jump to

Keyboard shortcuts

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