A Go library to build projects scaffolding CLIs on three main features:
- Initialization: interactive user configuration with huh (e.g. license choice, maintainers list, etc.)
- Parsing: repository languages parsing
- Generation: repository scaffolding with files generation based on Go template
go get -u github.com/kickr-dev/engine@latestInitialize (pkg.go.dev)
Runs an interactive form with huh
and alters the created configuration gradually with each huh.Group.
flowchart LR
subgraph Groups["Form pages (each a set of related questions)"]
direction TB
G1["Page 1"] --> G2["Page 2"] --> Gn["Page N"]
end
Groups --> F["Multi-step interactive form"]
F -->|"user answers each page"| C["filled config"]
Examples: see the package documentation.
Initialize: runs the interactive form and returns the filled configurationWithFormGroups: ordered list of huh groups to gradually fill the created configurationWithTeaOptions: options to tune the TUI (Terminal User Interface), native bubbletea options, underlying framework of huhErrRequiredField: specific error to return during groups validation to force user input
Generate (pkg.go.dev)
Parses a repository with all its configured parsers and then run all generators to create the appropriate files regarding the repository configuration, technologies, languages, etc.
flowchart TB
CFG["Repository config"] --> Parsing
subgraph Parsing["Detect repository info (in order)"]
direction LR
P1["Parser 1"] --> P2["Parser 2"] --> Pn["Parser N"]
end
Parsing --> CHK{"Something failed?"}
CHK -->|yes| ERR["Stop, nothing generated"]
CHK -->|no| Generation
subgraph Generation["Generate files (in order)"]
direction LR
G1["Generator 1"] --> G2["Generator 2"] --> Gn["Generator N"]
end
Generation --> CHK2{"Something failed?"}
CHK2 -->|yes| ERRF["Report what failed"]
CHK2 -->|no| OK["Repository generated"]
Examples: see the package documentation.
Generate: runs all given parsers then all given generators against a repositoryConfigure: appliesOptionFuncoptions (WithLogger,WithForce,WithFuncMap) globally before callingGenerateApplyTemplate: applies a singleTemplate(used internally byGeneratorTemplates/GeneratorModules)ApplyPatches: applies aTemplate'sPatcheson an already generated fileExecuteTemplate: executes a parsed Go template and writes it toout, honoring the givenEmptyPolicyFuncMap: returns the defaulttemplate.FuncMapused during Go templatingToSlug: slugifies an input stringGlobsWithPart: builds glob patterns for a template name, including its.partsubpartsDelimitersChevron/DelimitersBracket/DelimitersSquareBracket: predefinedDelimitersfor Go templatesNewLoggerURL: wraps anhttp.RoundTripperto log request URLs via the configuredLoggerNewTestLogger: creates aLoggerwriting to anio.Writer, intended for tests onlyWithLogger: provides a customLoggerimplementationWithForce: forces generation of all definedTemplate(useful when projects removed the generated notice)WithFuncMap: enriches defaulttemplate.FuncMapprovided during Go templatingGetLogger: gets configuredloggeroption at any point in the workflowForced: gets configuredforceoption at any point in the worflowShouldGenerate: returns whether a file should be generated according to itsGeneratePolicy(existence, emptiness, generated notice,PolicyAlways,Forced)IsEmpty: returns whether a given content is considered empty according to anEmptyPolicyGeneratorTemplates: returns aGeneratortaking a slice ofTemplateto generate from the base of the repository (real path depends on each templateOutattribute)GeneratorModules: returns aGeneratortaking a slice ofTemplateto generate from the base of eachModule(real path depends on each templateOutattribute). A module is a directory of a given repository, useful to handle files generation in monorepositories
PartExtension(.part): extension for template subparts, expected to be used withTmplExtensionPatchExtension(.patch): extension for template file patchesPolicyAlways/PolicyNone:GeneratePolicyvalues controlling whether a file is always generated or only per default behavior (defaultPolicyNone)PolicyKeep/PolicyRemove:EmptyPolicyvalues controlling whether an empty generated file is kept or removed (defaultPolicyRemove)TmplExtension(.tmpl): extension for template files
To avoid rewriting from scratch generic functions, the library also exposes helpers packages
pkg/files, pkg/generator and pkg/parser,
including non-exhaustively go.mod, go.work, package.json parsing, license and gitignore contents download.
Files (pkg.go.dev)
Read, write, validate and locate files across a directory tree.
Examples: see the package documentation.
ReadJSON/WriteJSON: reads/writes a JSON file into/from a Go valueReadYAML/WriteYAML: reads/writes a YAML file into/from a Go valueReadTOML/WriteTOML: reads/writes a TOML file into/from a Go valueReadJSONFunc/ReadYAMLFunc/ReadTOMLFunc: wraps the matchingReadfunction into thefunc(out any) errorsignatureValidateexpectsValidate: validates a file format against a JSON schema, returningValidationErroron failureErrNilRead: returned byValidatewhen a nil read function is providedExists: checks whether a provided path existsGlob: walks a directory tree to find specific files per globGlobExcludedDirectories: excludes specific directories from glob matchingGlobExcludedFiles: excludes specific files from glob matchingUmask: returns the running process' umask, computed once for the process' lifetime
Rw(0o600),RwRR(0o644),RwRwRw(0o666),RwxRxRxRx(0o755): file-mode constants
Generators (pkg.go.dev)
Fetches and downloads scaffolding content from external sources.
Examples: see the package documentation.
FetchGitignore: fetches a.gitignorefrom ToptalFetchCodeOfConduct: fetches the Contributor Covenant 3.0 markdown
CodeOfConductURL: Contributor Covenant 3.0 markdown source used byFetchCodeOfConductErrNoClient,ErrInvalidResponse,ErrNoTemplates: errors returned on invalid client, HTTP response or missing templatesFileCodeOfConduct(CODE_OF_CONDUCT.md): default code of conduct output filenameFileGitignore(.gitignore): default gitignore output filenameGitignoreBaseURL: Base URL to fetch gitignores from
Parsers (pkg.go.dev)
Detects and parses a repository's languages, tooling and configuration files.
Examples: see the package documentation.
Git: detects a Git repository by parsing its configuration (remote, platform, host, repository path, repository name and tags), returning aVCSstructReadGomod: detects a Golang repository by parsing itsgo.mod, returning aGomodstructReadGowork: detects a Golang repository by parsing itsgo.workand all itsusesgo.modReadHugo: detects a Hugo site by parsing itshugo.*configurationsMergeValues: merges multipleyamlfiles together into the inputvaluesPackageJSON.Validate: validates apackage.json(package manager requirement)ReadGoCmd: detects Go executables (CLIs, crons, jobs, workers) under acmdfolderGomod.AsVCS: converts a parsedGomodinto aVCSGowork.Module: returns the workspace's module pathExecutables.AddCLI/AddCron/AddJob/AddWorker: registers a detected executable by kindExecutables.Binaries: returns the total count of registered executables
Bitbucket,Gitea,GitHub,GitLab: recognized VCS platform identifiersErrMissingModuleStatement,ErrMissingGoStatement: errors returned on invalidgo.mod/go.workfilesErrMissingPackageName,ErrInvalidPackageManager: errors returned on invalidpackage.jsonfilesErrNoGowork: returned byReadGoworkwhen nogo.workfile is foundErrNoHugo: returned byReadHugowhen no Hugo configuration is foundFileGomod(go.mod): Go module file nameFileGowork(go.work): Go workspace file nameFileMain(main.go): Go main file nameFilePackageJSON(package.json): npm package manifest file nameFolderCMD(cmd): conventional Go commands folder name