Documentation
¶
Overview ¶
Package initcmd implements `fendix init` — zero-config workflow generator. It detects the project's stack and writes a default CI workflow plus a `.fendix-ignore` starter file.
Index ¶
Constants ¶
const ( CIGitHub = "github" CIGitLab = "gitlab" CICircleCI = "circleci" )
CI identifies the CI system whose templates `init` will emit. Sprint 17 added gitlab and circleci alongside the original github.
const UnknownCommit = "REPLACE_WITH_A_FENDIX_RELEASE_COMMIT"
UnknownCommit is written when the running binary does not know the commit it was built from (a dirty tree, or a Docker build without REVISION). The install step rejects it.
const UnreleasedVersion = "REPLACE_WITH_A_FENDIX_RELEASE_TAG"
UnreleasedVersion is what a build that is not a published release writes instead of a tag. The generated install step rejects anything that is not a release tag, so CI fails loudly until the user pins one.
Variables ¶
var SupportedCIs = []string{CIGitHub, CIGitLab, CICircleCI}
SupportedCIs is the canonical set `--ci` accepts. Used by the CLI flag validator and by tests that iterate over every shape.
Functions ¶
func DetectCI ¶
DetectCI returns the CI system detected in rootDir, or "" when none matches. Used by Run() when Options.CI is empty (the default). Ordering deliberately prefers GitHub when multiple markers are present, on the assumption that a project shipping multiple CI configurations has the GitHub workflow as its primary; a user who wants a different default passes --ci explicitly. (Sprint 17.)
func IsReleaseCommit ¶
IsReleaseCommit reports whether c is a full Git commit hash.
func IsReleaseVersion ¶
IsReleaseVersion reports whether v names a published Fendix release.
func Run ¶
Run executes `fendix init` end-to-end: detect → plan → write. It emits human-readable status lines to Options.Out. On success, the project will have a committable CI workflow + a starter ignore file.
Run returns *ErrFileExists when one of the target files already exists and --force was not set. Other errors are filesystem errors (mkdir, write) wrapped with context.
Types ¶
type Detection ¶
type Detection struct {
Stacks []Stack // all detected stacks (a polyglot repo has multiple)
Specs []SpecLocation // OpenAPI specs found at common paths
}
Detection bundles everything `init` figures out about the project.
func Detect ¶
Detect inspects rootDir and returns a Detection summarizing what was found. It does not error on a missing directory or unreadable files; callers get an empty Detection instead. Callers should treat an empty Detection.Stacks as "unknown / generic".
func (Detection) PrimaryStack ¶
PrimaryStack returns the first detected stack, or a "Generic" stack when none were detected. Used in the user-facing summary line.
func (Detection) SummaryLine ¶
SummaryLine returns a one-line human-readable description of what was detected, suitable for the init command's "✓ Detected: ..." line.
type ErrFileExists ¶
type ErrFileExists struct {
Path string
}
ErrFileExists is returned when a target file already exists and Force is not set. The error wraps the conflicting path.
func (*ErrFileExists) Error ¶
func (e *ErrFileExists) Error() string
type ErrUnsupportedCI ¶
type ErrUnsupportedCI struct {
CI string
}
ErrUnsupportedCI is returned when Options.CI is set to a value outside SupportedCIs.
func (*ErrUnsupportedCI) Error ¶
func (e *ErrUnsupportedCI) Error() string
type Options ¶
type Options struct {
// RootDir is the project root where files will be written. Defaults
// to the process working directory when empty.
RootDir string
// Force overwrites existing files. Without it, Run refuses to
// clobber any of the target paths and returns ErrFileExists.
Force bool
// Print writes generated content to Out instead of disk. Useful for
// previewing what `fendix init` would do before committing.
Print bool
// CI selects which CI-system templates to emit (Sprint 17). Empty
// means auto-detect from project files (see DetectCI in detect.go).
// Must be one of SupportedCIs or empty; invalid values cause Run
// to return ErrUnsupportedCI.
CI string
// Version is the running fendix's version (main.Version). Generated
// CI pins this release. A value that is not a release tag pins
// UnreleasedVersion instead and Run prints a warning.
Version string
// Revision is the commit the running fendix was built from. Generated
// CI fetches the installer at this commit. A value that is not a full
// commit hash pins UnknownCommit instead and Run prints a warning.
Revision string
// Out is where status lines and (when Print is true) generated
// content go. Defaults to os.Stdout when nil.
Out io.Writer
}
Options controls Run's behavior. Zero-value defaults are sensible.
type SpecLocation ¶
type SpecLocation struct {
Path string // e.g. "openapi.yaml", "api/openapi.json"
}
SpecLocation is a discovered OpenAPI spec path, relative to the project root.
type Stack ¶
type Stack struct {
Name string // e.g. "Python", "Node.js", "Go", "Generic"
Marker string // file that triggered the detection, e.g. "go.mod"
}
Stack represents a detected primary language/framework. The detection is deliberately coarse — `init` doesn't currently customize output per stack (the workflow template is generic), but the detected stack is reported to the user so they can sanity-check that fendix found the right project.