Documentation
¶
Index ¶
- Constants
- Variables
- func AddMutationFlags(cmd *cobra.Command, flags *MutationFlags)
- func AddOutputFlags(cmd *cobra.Command, flags *OutputFlags)
- func AddSilentFlag(cmd *cobra.Command)
- func AllSettings() map[string]interface{}
- func BashCompletionPath() string
- func BindFlags(cmd *cobra.Command, toolName string, useSharedConfig bool) error
- func BindFlagsWithPrefix(flags *pflag.FlagSet, prefix string) error
- func CacheHome() string
- func ConfigFileUsed() string
- func ConfigHome() string
- func DataHome() string
- func Debug()
- func DevloreCacheHome() string
- func DevloreConfigHome() string
- func DevloreDataHome() string
- func DevloreStateHome() string
- func DisplayManPage(cmd *cobra.Command, header *doc.GenManHeader) error
- func Error(format string, args ...interface{})
- func ExitCode(err error) int
- func ExitWith(code int, err error) error
- func Failure(format string, args ...interface{}) error
- func FishCompletionPath() string
- func Get(toolName, key string, useSharedConfig bool) interface{}
- func GetBool(toolName, key string, useSharedConfig bool) bool
- func GetInt(toolName, key string, useSharedConfig bool) int
- func GetString(toolName, key string, useSharedConfig bool) string
- func GetStringMap(toolName, key string, useSharedConfig bool) map[string]interface{}
- func GetStringSlice(toolName, key string, useSharedConfig bool) []string
- func InitViper(cfg ViperConfig) error
- func ManPath() string
- func NewConfigCmd(info ConfigInfo) *cobra.Command
- func NewHelpCmd(rootCmd *cobra.Command, header ManHeader) *cobra.Command
- func NewManCmd(rootCmd *cobra.Command, header ManHeader) *cobra.Command
- func NewSelfInstallCmd(rootCmd *cobra.Command, info SelfInstallInfo) *cobra.Command
- func NewVersionCmd(info VersionInfo) *cobra.Command
- func Note(format string, args ...interface{})
- func RegisterRepo(tool string, entry RepoEntry) error
- func Render(w io.Writer, data interface{}, flags OutputFlags) error
- func RenderMutation(w io.Writer, data interface{}, flags MutationFlags) error
- func RenderMutationTo(data interface{}, flags MutationFlags) error
- func RenderTo(data interface{}, flags OutputFlags) error
- func SetProgramName(name string)
- func SetSilent(s bool)
- func SharedConfigPath() string
- func StateHome() string
- func Success(format string, args ...interface{})
- func ToolConfigPath(toolName string) string
- func UnregisterRepo(tool, layer string) error
- func Warn(format string, args ...interface{})
- func ZshCompletionPath() string
- type ConfigInfo
- type ManHeader
- type Migration
- type MutationFlags
- type OutputFlags
- type ProjectInfo
- type RepoEntry
- type RepoScanResult
- type RepoStructure
- type SelfInstallInfo
- type VersionInfo
- type ViperConfig
Constants ¶
const ( ExitOK = 0 // Success ExitError = 1 // Generic error ExitUsage = 64 // Bad CLI syntax ExitDataErr = 65 // Invalid manifest/config ExitNoInput = 66 // File not found ExitSoftware = 70 // Internal error (bug) ExitCantCreate = 73 // Can't create file/symlink ExitIOErr = 74 // Read/write failure ExitNoPerm = 77 // Permission denied )
const DefaultFormat = "json"
DefaultFormat is the default output format (JSON for scriptability).
Variables ¶
var ErrManNotAvailable = errors.New("man command not available")
ErrManNotAvailable indicates the man command is not available on this system.
Functions ¶
func AddMutationFlags ¶
func AddMutationFlags(cmd *cobra.Command, flags *MutationFlags)
AddMutationFlags adds --passthru and --format flags for mutating commands. Mutating commands are silent by default; --passthru outputs what was changed. Usage:
var flags cli.MutationFlags cli.AddMutationFlags(cmd, &flags)
func AddOutputFlags ¶
func AddOutputFlags(cmd *cobra.Command, flags *OutputFlags)
AddOutputFlags adds --filter and --format flags to a command. Usage:
var output cli.OutputFlags cli.AddOutputFlags(cmd, &output)
func AddSilentFlag ¶
AddSilentFlag adds the --silent flag to a root command.
func AllSettings ¶
func AllSettings() map[string]interface{}
AllSettings returns all settings as a map.
func BashCompletionPath ¶
func BashCompletionPath() string
BashCompletionPath returns the bash completion directory. XDG_DATA_HOME/bash-completion/completions
func BindFlags ¶
BindFlags binds all persistent flags from a command to Viper. Call this after defining flags and before Execute().
Flags are bound with the tool's section prefix when using shared config:
- --repo flag → viper key "writ.repo" (with UseSharedConfig)
- --repo flag → viper key "repo" (without UseSharedConfig)
func BindFlagsWithPrefix ¶
BindFlagsWithPrefix binds flags with a custom prefix. Useful for subcommands that need their own config section.
Example:
BindFlagsWithPrefix(addCmd.Flags(), "writ.add") // --overwrite flag → viper key "writ.add.overwrite"
func ConfigFileUsed ¶
func ConfigFileUsed() string
ConfigFileUsed returns the config file path that Viper loaded. Returns empty string if no config file was found.
func DevloreCacheHome ¶
func DevloreCacheHome() string
DevloreCacheHome returns the unified devlore cache directory. XDG_CACHE_HOME/devlore
func DevloreConfigHome ¶
func DevloreConfigHome() string
DevloreConfigHome returns the unified devlore config directory. XDG_CONFIG_HOME/devlore
func DevloreDataHome ¶
func DevloreDataHome() string
DevloreDataHome returns the unified devlore data directory. XDG_DATA_HOME/devlore
func DevloreStateHome ¶
func DevloreStateHome() string
DevloreStateHome returns the unified devlore state directory. XDG_STATE_HOME/devlore
func DisplayManPage ¶
func DisplayManPage(cmd *cobra.Command, header *doc.GenManHeader) error
DisplayManPage generates a man page and displays it with the system pager. Returns ErrManNotAvailable if man is not available on this system.
func Error ¶
func Error(format string, args ...interface{})
Error prints an error message to stderr. Unlike Failure, this does not return an error—use for non-fatal errors. Format: [program] [✖] message (red ✖)
func ExitCode ¶
ExitCode extracts the exit code from an error. Returns the wrapped code if present, or ExitError (1) for plain errors.
func Failure ¶
Failure prints an error message to stderr and returns an error. Use when the operation cannot continue. Format: [program] [✖] message (red ✖)
func FishCompletionPath ¶
func FishCompletionPath() string
FishCompletionPath returns the fish completion directory. XDG_CONFIG_HOME/fish/completions
func Get ¶
Get retrieves a config value with the tool's section prefix. When using shared config, automatically prefixes with tool name.
Example:
Get("writ", "repo", true) → viper.Get("writ.repo")
Get("writ", "repo", false) → viper.Get("repo")
func GetStringMap ¶
GetStringMap retrieves a string map config value.
func GetStringSlice ¶
GetStringSlice retrieves a string slice config value.
func InitViper ¶
func InitViper(cfg ViperConfig) error
InitViper initializes Viper with standard devlore conventions. Call this in PersistentPreRunE of the root command.
Precedence (lowest to highest):
- Config file defaults
- Config file values
- Environment variables (TOOL_KEY_NAME)
- Command-line flags
Environment variable mapping:
- WRIT_REPO → writ.repo (with UseSharedConfig)
- WRIT_VARS_USER_NAME → writ.vars.user_name
- Dots become underscores, keys are case-insensitive
func ManPath ¶
func ManPath() string
ManPath returns the user man page directory: XDG_DATA_HOME/man/man1
func NewConfigCmd ¶
func NewConfigCmd(info ConfigInfo) *cobra.Command
NewConfigCmd creates the config command with git-style subcommands.
Dot-paths match the config file structure exactly. No implicit prefixing. "writ.repos.0.path" in the CLI reads writ.repos[0].path in the file. "secrets.mode" reads secrets.mode. WYSIWYG.
Usage:
tool config get <key>... # Get values tool config set <key>=<value>... # Set values tool config unset <key>... # Remove keys tool config list # List all settings tool config edit # Open in $EDITOR tool config validate # Validate against schema tool config schema # Output JSON schema tool config path # Show config file location
func NewHelpCmd ¶
NewHelpCmd creates a help command that prefers man pages when available. This follows git's model: if man pages are installed, display them via pager; otherwise fall back to console text output.
func NewManCmd ¶
NewManCmd creates the man command for displaying/installing man pages. Usage:
tool man # display man page with pager tool man --install # install to ~/.local/share/man/man1/ tool man deploy # display man page for subcommand
func NewSelfInstallCmd ¶
func NewSelfInstallCmd(rootCmd *cobra.Command, info SelfInstallInfo) *cobra.Command
NewSelfInstallCmd creates the self-install command. Usage:
./tool self-install ~/.local ./tool self-install ~/.local --shell bash --shell zsh ./tool self-install ~/.local --personal-repo=~/dotfiles
This performs complete installation:
- Copies binary to <root>/bin/
- Installs man pages to <root>/share/man/man1/ (if man command exists)
- Installs completions for detected shells (or specified via --shell)
- Initializes config in XDG_CONFIG_HOME/devlore/
- Initializes cache in XDG_CACHE_HOME/devlore/
- Scans and registers repos (if --personal-repo or --team-repo provided)
func NewVersionCmd ¶
func NewVersionCmd(info VersionInfo) *cobra.Command
NewVersionCmd creates the version command.
func Note ¶
func Note(format string, args ...interface{})
Note prints an informational message to stderr. Format: [program] [+] message (light gray +)
func RegisterRepo ¶
RegisterRepo registers a repository in the shared config file. If a repo with the same layer already exists, it is replaced.
func Render ¶
func Render(w io.Writer, data interface{}, flags OutputFlags) error
Render outputs data according to the format specification. Supported formats: json, yaml, table, or a Go template string.
func RenderMutation ¶
func RenderMutation(w io.Writer, data interface{}, flags MutationFlags) error
RenderMutation outputs data only if --passthru is set. Returns nil without output if passthru is false.
func RenderMutationTo ¶
func RenderMutationTo(data interface{}, flags MutationFlags) error
RenderMutationTo is a convenience function that renders to stdout if --passthru is set.
func RenderTo ¶
func RenderTo(data interface{}, flags OutputFlags) error
RenderTo is a convenience function that renders to stdout.
func SetProgramName ¶
func SetProgramName(name string)
SetProgramName sets the program name used in output prefixes.
func SharedConfigPath ¶
func SharedConfigPath() string
SharedConfigPath returns the path to the shared devlore config file.
func Success ¶
func Success(format string, args ...interface{})
Success prints a success message to stderr. Format: [program] [✔] message (green ✔)
func ToolConfigPath ¶
ToolConfigPath returns the path to a tool-specific config file.
func UnregisterRepo ¶
UnregisterRepo removes a repository for the given layer from the shared config.
func Warn ¶
func Warn(format string, args ...interface{})
Warn prints a warning message to stderr. Format: [program] [△] message (yellow △)
func ZshCompletionPath ¶
func ZshCompletionPath() string
ZshCompletionPath returns the zsh completion directory. XDG_DATA_HOME/zsh/site-functions
Types ¶
type ConfigInfo ¶
type ConfigInfo struct {
Name string // Tool name (e.g., "lore", "writ")
Schema []byte // Embedded JSON schema
DefaultConfig []byte // Default configuration content
}
ConfigInfo contains configuration metadata for a tool.
type Migration ¶
type Migration struct {
Issue string // what's wrong
Commands []string // suggested git commands to fix it
}
Migration describes a recommended migration step.
type MutationFlags ¶
MutationFlags holds flags for mutating commands (--passthru).
type OutputFlags ¶
OutputFlags holds the --filter and --format flag values.
type ProjectInfo ¶
type ProjectInfo struct {
Name string
Path string
Segment string // segment suffix (e.g., "Darwin", "Unix")
FileCount int
Templates int
Secrets int
}
ProjectInfo describes a detected project directory.
type RepoEntry ¶
type RepoEntry struct {
Layer string // "personal", "team", or "base"
Path string // Local filesystem path
URL string // Optional remote URL
Name string // Optional display name
}
RepoEntry represents a repository configuration entry.
type RepoScanResult ¶
type RepoScanResult struct {
Path string
// Git information
IsGit bool
Remote string
Branch string
Dirty int // count of uncommitted changes
GitError string
// Structure detection
Structure RepoStructure
HomePath string // path to detected Home-equivalent directory
Projects []ProjectInfo
NestedUnder string // non-empty if projects are nested (e.g., "Configs")
TemplateCount int
SecretCount int
HasRecipients bool
// Migration guidance
Migrations []Migration
}
RepoScanResult holds the results of scanning a potential writ repository.
func ScanRepo ¶
func ScanRepo(path string) *RepoScanResult
ScanRepo inspects a directory and reports on its suitability as a writ repository.
func (*RepoScanResult) NeedsMigration ¶
func (r *RepoScanResult) NeedsMigration() bool
NeedsMigration returns true if the scan found issues that require migration.
func (*RepoScanResult) PrintReport ¶
func (r *RepoScanResult) PrintReport()
PrintReport outputs the scan result to stderr.
type RepoStructure ¶
type RepoStructure int
RepoStructure describes the detected repository layout.
const ( StructureUnknown RepoStructure = iota StructureCompatible // Home/<project>/ with "." segments StructurePartial // Has Home/ but needs migration StructureTraditional // Dotfiles at root StructureStow // Stow-like packages at root )
func (RepoStructure) String ¶
func (s RepoStructure) String() string
String returns a human-readable label for the structure type.
type SelfInstallInfo ¶
type SelfInstallInfo struct {
Name string // Tool name (e.g., "lore", "writ")
ManHeader ManHeader // Man page header metadata
ConfigInfo ConfigInfo // Config schema and defaults
}
SelfInstallInfo contains metadata needed for self-installation.
type VersionInfo ¶
type VersionInfo struct {
Version string // Semantic version (e.g., "0.1.0")
Commit string // Git commit hash
BuildDate string // Build timestamp
}
VersionInfo contains version metadata set at build time.
type ViperConfig ¶
type ViperConfig struct {
// Name is the tool name (e.g., "lore", "writ")
Name string
// EnvPrefix is the environment variable prefix (e.g., "LORE", "WRIT")
// If empty, defaults to uppercase Name
EnvPrefix string
// ConfigName is the config file name without extension (default: "config")
ConfigName string
// ConfigType is the config file type (default: "yaml")
ConfigType string
// When true, config is read from the tool's section (e.g., config.writ.repo)
UseSharedConfig bool
}
ViperConfig holds configuration for Viper initialization.