Documentation
¶
Index ¶
- Variables
- func BuildAddSteps(targetDir string, deps map[int]tui.Dependency, versions map[string]string) []tui.InstallStep
- func BuildInstallSteps(targetPath string, req Requirement) []tui.InstallStep
- func BuildRemoveSteps(targetDir string, deps map[int]tui.Dependency) []tui.InstallStep
- func CheckBinary(name string) error
- func ComposeServiceNames(depIDs []string) []string
- func GitConfigUserName() string
- func PrepareNewProject(req Requirement) (targetPath string, err error)
- func PrintAudit(findings []AuditFinding, vulnAdvisory string)
- func PrintDocs(deps map[int]tui.Dependency)
- func PrintDoctor(checks []DoctorCheck)
- func PrintHistory(entries []HistoryEntry)
- func PrintInstalled(deps []InstalledDep)
- func ReadModulePath(dir string) (string, error)
- func RecordHistory(command, dir, detail string)
- func ResolveLicenseHolder() string
- func SnapshotForUndo(targetDir string) error
- func SuggestedPublishCommand() string
- func Undo(targetDir string) error
- func ValidLicenseKind(kind string) bool
- func VulnCheckAdvisory(dir string) string
- type AuditFinding
- type Config
- type DoctorCheck
- type HistoryEntry
- type InstalledDep
- type Requirement
Constants ¶
This section is empty.
Variables ¶
var ConfigKeys = []string{"license", "author", "modulePrefix"}
ConfigKeys are the recognized `genitz config set`/`get` keys, in display order — the single source of truth backing both Get/Set's validation and runConfig's default listing.
var Version = "0.1.0-dev"
Version is Genitz's own release version. The release pipeline (.goreleaser.yaml) overrides it at build time via -ldflags "-X .../generator.Version=vX.Y.Z" — ldflags -X can only target a var, not a const, hence this being one. `go install`/local builds that skip that step just get this literal default.
Functions ¶
func BuildAddSteps ¶
func BuildAddSteps(targetDir string, deps map[int]tui.Dependency, versions map[string]string) []tui.InstallStep
BuildAddSteps returns the ordered go get/go mod tidy steps for installing deps into the existing project at targetDir. versions optionally pins an import path to a specific version (see installArg) — pass nil for unpinned/latest installs (the interactive TUI never collects a version).
func BuildInstallSteps ¶
func BuildInstallSteps(targetPath string, req Requirement) []tui.InstallStep
BuildInstallSteps returns the ordered go mod/go get/go fmt steps for scaffolding req at targetPath — each one runnable independently so the caller (the TUI) can animate progress as they execute.
func BuildRemoveSteps ¶
func BuildRemoveSteps(targetDir string, deps map[int]tui.Dependency) []tui.InstallStep
BuildRemoveSteps returns the ordered go get <path>@none/go mod tidy steps for dropping deps from the project at targetDir. `go get <path>@none` is the documented way to remove a requirement — go mod tidy then cleans up anything left unreferenced (if the code still imports it, tidy will re-add it, which is correct: genitz can't know that without a full source scan, so it doesn't try).
func CheckBinary ¶
CheckBinary fails fast with a clear message when name isn't on PATH, instead of letting a raw exec.Command error surface mid-InstallStep animation (InstallStep failures are fatal, so the sooner the message the better — see runGitInit / go mod callers for where this is used).
func ComposeServiceNames ¶
ComposeServiceNames returns the compose service names (deduped, sorted) that the given dependency IDs would produce — main.go injects this into the TUI Model for the Docker step's live "docker-compose will include: ..." preview, so the tui package doesn't need its own copy of the dockerComposeServices table (and can't import generator to reuse this one — the dependency runs the other way).
func GitConfigUserName ¶
func GitConfigUserName() string
GitConfigUserName returns `git config --get user.name`'s value, or "" if git isn't on PATH, isn't configured, or the lookup otherwise fails — callers treat "" as "no default available" and fall back to a placeholder, so a failure here is never fatal.
func PrepareNewProject ¶
func PrepareNewProject(req Requirement) (targetPath string, err error)
PrepareNewProject validates req, creates the target directory, and writes a bare main.go. It's synchronous and network-free — the animated part (go mod / go get) is BuildInstallSteps, run separately so the TUI can show progress for it.
func PrintAudit ¶
func PrintAudit(findings []AuditFinding, vulnAdvisory string)
PrintAudit renders AuditProject's results.
func PrintDocs ¶
func PrintDocs(deps map[int]tui.Dependency)
PrintDocs lists what got installed and where to read up on each one — pkg.go.dev renders a module's README plus its API docs for any import path, so it's a correct reference without hand-curating a link per dep.
func PrintDoctor ¶
func PrintDoctor(checks []DoctorCheck)
PrintDoctor renders RunDoctor's results — a check mark per line, with required failures called out distinctly from advisory ones.
func PrintHistory ¶
func PrintHistory(entries []HistoryEntry)
PrintHistory renders ReadHistory's result as a table.
func PrintInstalled ¶
func PrintInstalled(deps []InstalledDep)
PrintInstalled renders ListInstalled's result as a table — registry matches show name/category, unmatched import paths are marked unmanaged rather than silently omitted, since they're still real entries in go.mod.
func ReadModulePath ¶
ReadModulePath reads the module directive from go.mod in dir.
func RecordHistory ¶
func RecordHistory(command, dir, detail string)
RecordHistory appends one entry to the local history log — best-effort, any failure here (no config dir, disk full, ...) is silently swallowed since a logging failure must never break the actual operation it's recording.
func ResolveLicenseHolder ¶
func ResolveLicenseHolder() string
ResolveLicenseHolder returns the best available default copyright holder: git config user.name first, then the persisted genitz config's author (`genitz config set author "..."`), else "" — licenseContent falls back to the [COPYRIGHT HOLDER] placeholder from there.
func SnapshotForUndo ¶
SnapshotForUndo copies go.mod (required) and go.sum (if present) from targetDir into that project's undo directory, overwriting any previous snapshot — deliberately LIFO/single-level, not a full history tree, to keep `genitz undo` predictable ("undoes the last add/remove") instead of needing its own navigation UI. Called right before BuildAddSteps/ BuildRemoveSteps run; a failure here is returned (unlike RecordHistory's silent best-effort) since it means `genitz undo` silently can't help — worth surfacing, though callers should still let the actual add/remove proceed rather than treat it as fatal.
func SuggestedPublishCommand ¶
func SuggestedPublishCommand() string
SuggestedPublishCommand returns the command to actually publish the repo to GitHub — deliberately not run automatically. gh repo creation is a real external side effect with a visibility decision the user should make explicitly, and InstallStep failures are fatal, so a missing/ unauthenticated gh shouldn't be able to abort an otherwise-successful scaffold.
func Undo ¶
Undo restores the most recent snapshot for targetDir over its current go.mod/go.sum. Scope is deliberately narrow: it only reverts what SnapshotForUndo captured (go.mod/go.sum), not any other file — genitz doesn't track a full diff, so it doesn't pretend to offer one.
func ValidLicenseKind ¶
ValidLicenseKind reports whether kind is a value licenseContent recognizes ("" for none, "mit", or "apache-2.0") — main.go uses this to fail fast on an unrecognized --license value instead of silently generating no LICENSE file.
func VulnCheckAdvisory ¶
VulnCheckAdvisory runs `govulncheck ./...` in dir if the binary is on PATH and returns a short advisory string to print after a successful install — "" when govulncheck isn't installed (nothing to report, not a failure) or when it found nothing. This is advisory-only, never fatal: InstallStep failures abort the whole run, and a known vulnerability in a freshly-picked dependency shouldn't block scaffolding the project.
Types ¶
type AuditFinding ¶
type AuditFinding struct {
ImportPath string
Name string
Kind string // "deprecated" or "unmanaged"
Detail string
ReplacementID string // set only for Kind == "deprecated"
}
AuditFinding is one issue AuditProject surfaced about an installed dependency.
func AuditProject ¶
func AuditProject(dir string) (findings []AuditFinding, vulnAdvisory string, err error)
AuditProject cross-references dir's direct dependencies (via ListInstalled) against deprecatedReplacements, flagging any match — the reverse direction of the picker: instead of curating what to add, it curates what's already there. Also returns govulncheck's advisory, if available, so `genitz audit` is one place to check both curation quality and known vulnerabilities.
type Config ¶
type Config struct {
License string `json:"license"`
Author string `json:"author"`
ModulePrefix string `json:"modulePrefix"`
}
Config holds genitz's persistent user-level defaults — set via `genitz config set <key> <value>`, applied by runInitFlags when the corresponding flag isn't passed.
func LoadConfig ¶
LoadConfig reads the persisted config, returning a zero Config (not an error) when no file exists yet — an unconfigured genitz is the default state, not a failure.
type DoctorCheck ¶
type DoctorCheck struct {
Name string
OK bool
Required bool // a failing required check is a real blocker, not advisory
Detail string
}
DoctorCheck is one diagnostic result from RunDoctor.
func RunDoctor ¶
func RunDoctor() []DoctorCheck
RunDoctor runs the environment diagnostics genitz depends on, so a user sees what's missing up front instead of hitting a confusing failure mid-InstallStep. go is required (same binary CheckBinary gates on); git/docker/gh are advisory since genitz never requires them itself — Docker files are only generated, never run, and gh is only suggested.
type HistoryEntry ¶
type HistoryEntry struct {
Time time.Time `json:"time"`
Command string `json:"command"`
Dir string `json:"dir"`
Detail string `json:"detail"`
}
HistoryEntry is one recorded genitz operation.
func ReadHistory ¶
func ReadHistory() ([]HistoryEntry, error)
ReadHistory returns recorded entries oldest-first, or nil (not an error) if nothing's been recorded yet.
type InstalledDep ¶
type InstalledDep struct {
ImportPath string
Version string
Name string // "" when the import path has no registry match
Category string
Managed bool // true when it matches a registry entry
}
InstalledDep is one entry from go.mod's require block, cross-referenced against the dependency registry so `genitz list` can show a friendly name and category instead of a bare import path.
func ListInstalled ¶
func ListInstalled(dir string) ([]InstalledDep, error)
ListInstalled reads the direct requires from go.mod in dir (indirect ones are skipped — they're transitive, not something the user picked) and cross-references each import path against tui.DependencyRegistry.
type Requirement ¶
type Requirement struct {
ProjectName string
PackageName string
Deps map[int]tui.Dependency
IncludeDocker bool
IncludeCI bool
IncludeMakefile bool
IncludeGitInit bool
IncludeReadme bool
// IncludeCommunityFiles bundles CONTRIBUTING.md, SECURITY.md, GitHub
// issue templates, and (if IncludeCI is also on) .github/dependabot.yml
// — one toggle rather than four, same "keep the extras list short"
// spirit as the other checkboxes.
IncludeCommunityFiles bool
// License is one of "", "none", "mit", "apache-2.0" — "" and "none" both
// mean "generate nothing", kept as two spellings so the zero value (flag
// not passed / TUI default) behaves the same as an explicit "none".
License string
// DepVersions maps an import path to a pinned version (e.g. "v2.50.0"),
// used by --deps id@version in the non-interactive flag flow. Nil/missing
// entries install unpinned (latest), same as before this field existed.
DepVersions map[string]string
}
Requirement describes everything needed to scaffold a new project.
func CheckPreconditions ¶
func CheckPreconditions(req Requirement) (Requirement, error)
CheckPreconditions validates req (including the git-on-PATH check when IncludeGitInit is set) and confirms the target directory doesn't already exist — without creating anything. It's what makes --dry-run an accurate preview instead of one that can report success for a run that would immediately fail; PrepareNewProject calls it too, so the real run and the dry-run share exactly one precondition check.
func NewRequirementFromModel ¶
func NewRequirementFromModel(m *tui.Model) (Requirement, error)
NewRequirementFromModel converts the interactive model into a concrete Requirement.