Documentation
¶
Overview ¶
Package tui implements the interactive `dotdrift generate` wizard.
The wizard is split in two layers:
- a pure spec-builder state machine (this package's MountsWizard / SmbWizard and the choice types) that accumulates user choices and assembles generate.Input through the SAME assembly helpers the CLI mode uses (MountsInput / SmbInput / ParseShareFlags). It is hermetically testable: feed choices, get a generate.Input, write with Write — no TTY involved. CLI mode and wizard mode therefore produce byte-identical module trees for the same logical inputs.
- a thin huh presentation layer (wizard_mounts.go, wizard_smb.go) that gathers the same choices interactively and feeds the state machine. lipgloss renders the minimal tab chrome (mounts | smb).
Write semantics: the mounts wizard accumulates every mount and calls generate.WriteModule ONCE at the end (WriteModule replaces [mounts] wholesale, so a mid-loop write would wipe earlier iterations). The smb wizard writes once after the shares loop. Aborting (ctrl+c/esc) before the final confirmation discards all unwritten choices.
Index ¶
- func ExistingMountSources(root string, sel generate.Selection) ([]string, error)
- func InvokingUser() (uid int, gid int, username string, err error)
- func MountsInput(mounts map[string]profile.MountSpec, uid, gid int) generate.Input
- func ParseShareFlags(raw []string, writable, public bool) (map[string]profile.ShareSpec, error)
- func PrintSummary(out io.Writer, root string, sel generate.Selection) error
- func ResolveWritable(writableFlag *bool, readonly bool) bool
- func RunMountsWizard(ctx context.Context, p MountsParams) error
- func RunSmbWizard(ctx context.Context, p SmbParams) error
- func SmbInput(group string, users []string, avahi *bool, shares map[string]profile.ShareSpec, ...) generate.Input
- func ValidateNetworkSource(s string) error
- type MountChoice
- type MountsParams
- type MountsWizard
- type ShareChoice
- type SmbParams
- type SmbServerChoice
- type SmbWizard
- type VolumeChoice
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExistingMountSources ¶
ExistingMountSources returns the mount sources the target module already manages (for MANAGED volume marking), sorted by mount name. An absent module yields nil, nil; a malformed module.toml is a loud error.
func InvokingUser ¶
InvokingUser resolves the invoking OS user: numeric uid/gid for mount-option token expansion and the username for smb's default user list. Unparseable numeric ids are an error.
func MountsInput ¶
MountsInput assembles a mounts generate.Input, defaulting each mount's empty state to "enabled" (the CLI's --state default).
func ParseShareFlags ¶
ParseShareFlags validates and decodes --share name=path values into share specs with the resolved writable/public applied to every share. At least one share is required; both sides of the "=" must be non-empty.
func PrintSummary ¶
PrintSummary lists what a generate run materialized: the module dir and its files, name-sorted, written to the caller's writer (stdout for the CLI, stderr for the wizard).
func ResolveWritable ¶
ResolveWritable applies the shared writable-flag semantics: writable defaults on, an explicit --writable/--no-writable wins, and --readonly is the shorthand for --no-writable (winning when both are given).
func RunMountsWizard ¶
func RunMountsWizard(ctx context.Context, p MountsParams) error
RunMountsWizard runs the interactive mounts wizard: tab chrome, the target steps, the per-mount loop, and a single WriteModule at the end. Aborting (ctrl+c/esc) exits cleanly with nothing written.
func RunSmbWizard ¶
RunSmbWizard runs the interactive smb wizard: tab chrome, the server form, the shares loop, and a single WriteModule at the end. Aborting (ctrl+c/esc) exits cleanly with nothing written.
func SmbInput ¶
func SmbInput(group string, users []string, avahi *bool, shares map[string]profile.ShareSpec, defaultUser string, uid, gid int) generate.Input
SmbInput assembles an smb generate.Input, applying the shared defaults: an empty user list becomes the invoking user, an empty group becomes "smb". Avahi passes through untouched: nil keeps the default-on semantics, an explicit false records --no-avahi.
func ValidateNetworkSource ¶
ValidateNetworkSource accepts nfs-style "host:/export" and cifs-style "//host/share" sources; anything else is rejected with a message naming both accepted shapes.
Types ¶
type MountChoice ¶
type MountChoice struct {
Name string
Source string
Destination string
Type string
// Options overrides the registry preset when non-nil; nil means
// "registry preset applies" (identical to the CLI with no --option).
Options []string
// StartAt adds a .timer/.service pair when non-empty.
StartAt string
// State is "enabled" or "disabled"; empty defaults to enabled.
State string
}
MountChoice is one fully specified mount: one iteration of the mounts wizard loop, or the pre-fill derived from parsed CLI flags.
type MountsParams ¶
type MountsParams struct {
// Target selection inputs (the generate flags, not wizard input
// flags): empty layer means "ask", empty module id defaults in the
// form.
Profile string
Layer string
ModuleID string
Hostname string
Username string
// Input-flag pre-fill for the first mount iteration.
Name string
Source string
Destination string
Type string
Options []string
StartAt string
State string
}
MountsParams starts a mounts wizard run.
func (MountsParams) Prefill ¶
func (p MountsParams) Prefill() MountChoice
Prefill derives the first mount iteration's defaults from the parsed input flags.
type MountsWizard ¶
type MountsWizard struct {
// contains filtered or unexported fields
}
MountsWizard is the mounts spec-builder state machine: choices accumulate via AddMount and a single Write materializes the module.
func NewMountsWizard ¶
func NewMountsWizard(sel generate.Selection, reg *generate.Registry) *MountsWizard
NewMountsWizard starts a mounts wizard run for the target selection.
func (*MountsWizard) AddMount ¶
func (w *MountsWizard) AddMount(c MountChoice) error
AddMount validates and accumulates one mount choice; a later choice with the same name replaces the earlier one (matching the whole-entry-by-name merge of [mounts.<name>]).
func (*MountsWizard) Input ¶
func (w *MountsWizard) Input(uid, gid int) generate.Input
Input assembles the final generate.Input through the shared assembly.
func (*MountsWizard) Mounts ¶
func (w *MountsWizard) Mounts() map[string]profile.MountSpec
Mounts returns the accumulated mount specs (name order not guaranteed; use Input for the deterministic assembly).
func (*MountsWizard) Selection ¶
func (w *MountsWizard) Selection() generate.Selection
Selection returns the wizard's target selection.
type ShareChoice ¶
type ShareChoice struct {
// Writable and Public are per-share answers; the wizard defaults
// writable=yes / public=no like the CLI flags.
}
ShareChoice is one fully specified samba share: one iteration of the smb wizard shares loop.
type SmbParams ¶
type SmbParams struct {
Profile string
Layer string
ModuleID string
Hostname string
Username string
// Input-flag pre-fill.
Group string
Users []string
Avahi *bool
Writable *bool
Readonly bool
Public bool
}
SmbParams starts an smb wizard run.
func (SmbParams) PrefillShares ¶
func (p SmbParams) PrefillShares() ([]ShareChoice, error)
PrefillShares decodes the raw share flags into wizard share choices with the flag-resolved writable/public applied, mirroring the CLI's assembly. An empty Shares list yields nil (the shares loop starts fresh).
type SmbServerChoice ¶
type SmbServerChoice struct {
Group string
Users []string
// Avahi is nil for the default-on answer ("yes"); an explicit false
// records avahi = false like --no-avahi.
Avahi *bool
}
SmbServerChoice carries the server-level smb answers.
type SmbWizard ¶
type SmbWizard struct {
// contains filtered or unexported fields
}
SmbWizard is the smb spec-builder state machine: the server choice is set once, shares accumulate via AddShare, and a single Write materializes the module.
func NewSmbWizard ¶
NewSmbWizard starts an smb wizard run for the target selection.
func (*SmbWizard) AddShare ¶
func (w *SmbWizard) AddShare(c ShareChoice) error
AddShare validates and accumulates one share choice.
func (*SmbWizard) SetServer ¶
func (w *SmbWizard) SetServer(c SmbServerChoice)
SetServer records the server-level answers.
type VolumeChoice ¶
type VolumeChoice struct {
Volume generate.Volume
// Type is the kernel-recommended registry entry for the volume's
// filesystem family; empty when no entry is eligible.
Type string
// Name defaults to the volume label, else a short UUID prefix.
Name string
// Destination defaults to /mnt/<Name>.
Destination string
}
VolumeChoice is a detected local volume plus the wizard defaults derived from it: the kernel-recommended filesystem type, a default mount name, and a default destination.
func VolumeChoices ¶
func VolumeChoices(reg *generate.Registry, vols []generate.Volume) []VolumeChoice
VolumeChoices converts detected volumes into wizard choices. The recommended type preselects the kernel-Recommended entry for the volume's fstype family (lsblk "ntfs" matches the ntfs family of ntfs3/ntfs-3g). Already-managed volumes keep their Managed mark for the label.
func (VolumeChoice) Label ¶
func (c VolumeChoice) Label() string
Label renders the choice for the volume picker, marking already-managed volumes.