Documentation
¶
Overview ¶
Package codegen generates the cobra CLI commands from the api/spec/json specifications. It is a port of the PowerShell scripts under scripts/build-cli and reproduces their output byte-for-byte.
Index ¶
- func GenerateCommand(spec *Value, parentName string) (fileName string, src []byte)
- func GenerateRootCommand(spec *Value) (fileName string, src []byte)
- func GenerateSpec(data []byte, outputDir string) ([]GeneratedFile, []Warning, error)
- func GenerateSpecFile(specPath string, outputDir string) ([]GeneratedFile, []Warning, error)
- func ListSpecFiles(specDir string) ([]string, error)
- type GeneratedFile
- type Kind
- type Value
- type Warning
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateCommand ¶
GenerateCommand ports New-C8yApiGoCommand.ps1: it renders the unformatted source of one <alias>.auto.go subcommand file. parentName is the parent group package name (lowercased, dashes replaced).
func GenerateRootCommand ¶
GenerateRootCommand ports New-C8yApiGoRootCommand.ps1: it renders the unformatted source of the <group>.auto.go root command file that registers all subcommands of a group.
func GenerateSpec ¶
func GenerateSpec(data []byte, outputDir string) ([]GeneratedFile, []Warning, error)
GenerateSpec generates all output files for one specification document. The returned list is empty when the spec is skipped. Formatting matches the PowerShell pipeline: root commands are gofmt-ed, subcommands run through goimports (which also removes the unused imports of the template).
func GenerateSpecFile ¶
func GenerateSpecFile(specPath string, outputDir string) ([]GeneratedFile, []Warning, error)
GenerateSpecFile generates all output files for one specification file.
func ListSpecFiles ¶
ListSpecFiles returns the json specification files of a directory in name order.
Types ¶
type GeneratedFile ¶
type GeneratedFile struct {
// RelPath is the file path relative to the output directory (pkg/cmd),
// e.g. "alarms/list/list.auto.go".
RelPath string
// Source is the formatted Go source.
Source []byte
}
GeneratedFile is one formatted output file of a specification.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value is an ordered, loosely typed JSON value. It mirrors how PowerShell's ConvertFrom-Json exposes the specification data: object keys keep their document order and member access is case-insensitive.
func (*Value) Get ¶
Get returns the named member of an object (case-insensitive, like PowerShell property access). Returns nil when missing or when v is not an object. Safe to call on a nil receiver.
func (*Value) Items ¶
Items coerces the value to an array the way PowerShell's [array] cast does: nil stays empty, arrays return their elements and scalars become a single-element array.
func (*Value) Str ¶
Str renders the value the way PowerShell string interpolation does: null -> "", bool -> True/False, numbers use their literal form.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package powershell generates the PSc8y PowerShell module cmdlets and Pester tests from the api/spec/json specifications and packages the module.
|
Package powershell generates the PSc8y PowerShell module cmdlets and Pester tests from the api/spec/json specifications and packages the module. |