Documentation
¶
Index ¶
- Constants
- Variables
- func CopyTemplateFiles(sourceDir, destDir string, force bool, projectName string, ...) error
- func GenInternalTemplates() error
- func GetTemplateDir(subDir string) (string, error)
- func IsTemplateURL(templateNamePathOrURL string) bool
- func ValidateProjectName(s string) error
- type FieldTemplate
- type FieldType
- type ProjectTemplate
- type StackTemplate
- type Template
- type TemplateRepository
Constants ¶
const ( // BaseTemplateDir is the name of the directory containing templates. BaseTemplateDir = "templates" // InternalTemplateDir is the name of the directory containing internal templates. InternalTemplateDir = "templates/internal" // ExternalTemplateDir is the name of the directory containing external templates. ExternalTemplateDir = "templates/external" // GitDir is the name of the folder git uses to store information. GitDir = ".git" // KusionYaml is a config file which describe all params of a template KusionYaml = "kusion.yaml" )
Variables ¶
var (
// The Git URL for Kusion program templates
KusionTemplateGitRepository = "https://github.com/KusionStack/kusion-templates"
)
These are variables instead of constants in order that they can be set using the `-X` `ldflag` at build time, if necessary.
Functions ¶
func CopyTemplateFiles ¶
func CopyTemplateFiles( sourceDir, destDir string, force bool, projectName string, projectConfigs map[string]interface{}, stack2Configs map[string]map[string]interface{}, ) error
CopyTemplateFiles does the actual copy operation to a destination directory.
func GenInternalTemplates ¶
func GenInternalTemplates() error
GenInternalTemplates save localTemplates(FS) to internal-templates(target directory)
func GetTemplateDir ¶
GetTemplateDir returns the directory in which templates on the current machine are stored.
func IsTemplateURL ¶
IsTemplateURL returns true if templateNamePathOrURL starts with "https://".
func ValidateProjectName ¶
ValidateProjectName ensures a project name is valid, if it is not it returns an error with a message suitable for display to an end user.
Types ¶
type FieldTemplate ¶
type FieldTemplate struct { // Name represents the field name, required Name string `json:"name" yaml:"name"` // Description represents the field description, optional Description string `json:"description,omitempty" yaml:"description,omitempty"` // Type can be string/int/bool/float/array/struct, required Type FieldType `json:"type" yaml:"type"` // Default represents primitive field default value Default interface{} `json:"default,omitempty" yaml:"default,omitempty"` // Elem is active only when type is ArrayField Elem *FieldTemplate `json:"elem,omitempty" yaml:"elem,omitempty"` // Fields is active only when type is StructField Fields []*FieldTemplate `json:"fields,omitempty" yaml:"fields,omitempty"` }
func (*FieldTemplate) RestoreActualValue ¶
func (f *FieldTemplate) RestoreActualValue(input string) (actual interface{}, err error)
type ProjectTemplate ¶
type ProjectTemplate struct { // ProjectName is a required fully qualified name. ProjectName string `json:"projectName" yaml:"projectName"` // Description is an optional description of the template. Description string `json:"description,omitempty" yaml:"description,omitempty"` // Quickstart contains optional text to be displayed after template creation. Quickstart string `json:"quickstart,omitempty" yaml:"quickstart,omitempty"` // CommonTemplates contains configuration in project level CommonTemplates []*FieldTemplate `json:"common,omitempty" yaml:"common,omitempty"` // StackTemplates contains configuration in stack level StackTemplates []*StackTemplate `json:"stacks,omitempty" yaml:"stacks,omitempty"` }
ProjectTemplate is a Kusion project template manifest.
func LoadProjectTemplate ¶
func LoadProjectTemplate(path string) (*ProjectTemplate, error)
LoadProjectTemplate reads a project definition from a file.
type StackTemplate ¶
type StackTemplate struct { // Name is stack name Name string `json:"name" yaml:"name"` // Fields contains all fields wait to be prompt Fields []*FieldTemplate `json:"fields,omitempty" yaml:"fields,omitempty"` }
type Template ¶
type Template struct { Dir string // The directory containing kusion.yaml. Name string // The name of the template. // following fields come from ProjectTemplate ProjectName string // The name of the project. Description string // Description of the template. Quickstart string // Optional text to be displayed after template creation. CommonConfigs []*FieldTemplate // CommonConfigs contains configuration in stack level StackConfigs []*StackTemplate // StackConfigs contains configuration in stack level }
Template represents a project template.
func LoadTemplate ¶
LoadTemplate returns a template from a path.
type TemplateRepository ¶
type TemplateRepository struct { Root string // The full path to the root directory of the repository. SubDirectory string // The full path to the sub directory within the repository. ShouldDelete bool // Whether the root directory should be deleted. }
TemplateRepository represents a repository of templates.
func RetrieveTemplates ¶
func RetrieveTemplates(templateNamePathOrURL string, online bool) (TemplateRepository, error)
func (TemplateRepository) Delete ¶
func (repo TemplateRepository) Delete() error
Delete deletes the template repository.
func (TemplateRepository) Templates ¶
func (repo TemplateRepository) Templates() ([]Template, error)
Templates lists the templates in the repository.