Documentation ¶
Overview ¶
Package kcl defines the top-level interface for KCL.
Index ¶
- func GetFullSchemaType(pathList []string, schemaName string, opts ...Option) ([]*gpyrpc.KclType, error)
- func GetFullSchemaTypeMapping(pathList []string, schemaName string, opts ...Option) (map[string]*gpyrpc.KclType, error)
- func GetSchemaType(filename string, src any, schemaName string) ([]*gpyrpc.KclType, error)
- func GetSchemaTypeMapping(filename string, src any, schemaName string) (map[string]*gpyrpc.KclType, error)
- func Service() api.ServiceClient
- func SplitDocuments(s string) ([]string, error)
- type Hook
- type Hooks
- type KCLResult
- func (m *KCLResult) Get(key string, target ...interface{}) interface{}
- func (m *KCLResult) GetValue(key string, target ...interface{}) (value interface{}, err error)
- func (m *KCLResult) JSONString() string
- func (p *KCLResult) ToBool() (*bool, error)
- func (p *KCLResult) ToFloat64() (*float64, error)
- func (p *KCLResult) ToInt() (*int, error)
- func (p *KCLResult) ToList() ([]interface{}, error)
- func (p *KCLResult) ToMap() (map[string]interface{}, error)
- func (p *KCLResult) ToString() (string, error)
- func (p *KCLResult) ToType(target interface{}) error
- func (m *KCLResult) YAMLString() string
- type KCLResultList
- func ExecResultToKCLResult(o *Option, resp *gpyrpc.ExecProgram_Result, logger io.Writer, hooks Hooks) (*KCLResultList, error)
- func MustRun(path string, opts ...Option) *KCLResultList
- func Run(path string, opts ...Option) (*KCLResultList, error)
- func RunFiles(paths []string, opts ...Option) (*KCLResultList, error)
- func RunWithOpts(opts ...Option) (*KCLResultList, error)
- func (p *KCLResultList) First() *KCLResult
- func (p *KCLResultList) Get(i int) *KCLResult
- func (p *KCLResultList) GetRawJsonResult() string
- func (p *KCLResultList) GetRawYamlResult() string
- func (p *KCLResultList) Len() int
- func (p *KCLResultList) Slice() []KCLResult
- func (p *KCLResultList) Tail() *KCLResult
- func (p *KCLResultList) ToBool() (*bool, error)
- func (p *KCLResultList) ToFloat64() (*float64, error)
- func (p *KCLResultList) ToInt() (*int, error)
- func (p *KCLResultList) ToList() ([]interface{}, error)
- func (p *KCLResultList) ToMap() (map[string]interface{}, error)
- func (p *KCLResultList) ToString() (string, error)
- func (p *KCLResultList) ToType(target interface{}) error
- type KclType
- type Option
- func NewOption() *Option
- func ParseArgs(pathList []string, opts ...Option) (Option, error)
- func WithCode(codes ...string) Option
- func WithDisableNone(disableNone bool) Option
- func WithExternalPkgNameAndPath(name, path string) Option
- func WithExternalPkgs(key_value_list ...string) Option
- func WithFullTypePath(fullTypePath bool) Option
- func WithIncludeSchemaTypePath(includeSchemaTypePath bool) Option
- func WithKFilenames(filenames ...string) Option
- func WithLogger(l io.Writer) Option
- func WithOptions(key_value_list ...string) Option
- func WithOverrides(overrides ...string) Option
- func WithPrintOverridesAST(printOverrideAst bool) Option
- func WithSelectors(selectors ...string) Option
- func WithSettings(filename string) Option
- func WithShowHidden(showHidden bool) Option
- func WithSortKeys(sortKeys bool) Option
- func WithWorkDir(s string) Option
- type VersionResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetFullSchemaType ¶ added in v0.7.0
func GetFullSchemaType(pathList []string, schemaName string, opts ...Option) ([]*gpyrpc.KclType, error)
GetFullSchemaType returns the full schema types for the given schema name from a list of KCL file paths.
Parameters:
- pathList: A list of KCL file paths.
- schemaName: The name of the schema to get the types for.
- opts: Additional options to configure the processing.
Returns:
- A slice of pointers to KclType representing the full schema types.
- An error if there is any failure in the process.
func GetFullSchemaTypeMapping ¶ added in v0.9.0
func GetFullSchemaTypeMapping(pathList []string, schemaName string, opts ...Option) (map[string]*gpyrpc.KclType, error)
GetFullSchemaTypeMapping returns the full schema type mapping for the given schema name from a list of KCL file paths.
Parameters:
- pathList: A list of KCL file paths.
- schemaName: The name of the schema to get the type mapping for.
- opts: Additional options to configure the processing.
Returns:
- A map where the key is the schema name and the value is a pointer to KclType representing the schema type.
- An error if there is any failure in the process.
func GetSchemaType ¶
GetSchemaType returns the schema types associated with the given schema name from a KCL file or source code provided.
Parameters:
- filename: The name of the KCL file.
- src: The source content of the KCL file, which can be one of string, []byte or io.Reader types.
- schemaName: The name of the schema to get the types for.
Returns:
- A slice of pointers to KclType representing the schema types.
- An error if there is any failure in the process.
func GetSchemaTypeMapping ¶ added in v0.5.1
func GetSchemaTypeMapping(filename string, src any, schemaName string) (map[string]*gpyrpc.KclType, error)
GetSchemaTypeMapping returns the schema type mapping for the given schema name from a KCL file or source code provided.
Parameters:
- filename: The name of the KCL file.
- src: The source content of the KCL file, which can be one of string, []byte or io.Reader types.
- schemaName: The name of the schema to get the type mapping for.
Returns:
- A map where the key is the schema name and the value is a pointer to KclType representing the schema type.
- An error if there is any failure in the process.
func Service ¶ added in v0.9.2
func Service() api.ServiceClient
Service returns the interaction interface between KCL Go SDK and KCL Rust core.
func SplitDocuments ¶ added in v0.9.0
SplitDocuments returns a slice of all documents contained in a YAML string. Multiple documents can be divided by the YAML document separator (---). It allows for white space and comments to be after the separator on the same line, but will return an error if anything else is on the line.
Types ¶
type Hook ¶ added in v0.8.0
type Hook interface {
Do(o *Option, r *gpyrpc.ExecProgram_Result) error
}
type KCLResult ¶
type KCLResult struct {
// contains filtered or unexported fields
}
KCLResult denotes the result for the Run API.
func (*KCLResult) JSONString ¶
func (*KCLResult) YAMLString ¶
type KCLResultList ¶
type KCLResultList struct {
// contains filtered or unexported fields
}
func ExecResultToKCLResult ¶ added in v0.8.0
func ExecResultToKCLResult(o *Option, resp *gpyrpc.ExecProgram_Result, logger io.Writer, hooks Hooks) (*KCLResultList, error)
func MustRun ¶
func MustRun(path string, opts ...Option) *KCLResultList
func RunWithOpts ¶
func RunWithOpts(opts ...Option) (*KCLResultList, error)
RunWithOpts is the same as Run, but it does not require a path as input. Note: you need to specify the path in options by method WithKFilenameList() or the workdir in method WorkDir(), or it will return an error.
func (*KCLResultList) First ¶
func (p *KCLResultList) First() *KCLResult
func (*KCLResultList) Get ¶
func (p *KCLResultList) Get(i int) *KCLResult
func (*KCLResultList) GetRawJsonResult ¶
func (p *KCLResultList) GetRawJsonResult() string
func (*KCLResultList) GetRawYamlResult ¶
func (p *KCLResultList) GetRawYamlResult() string
func (*KCLResultList) Len ¶
func (p *KCLResultList) Len() int
func (*KCLResultList) Slice ¶
func (p *KCLResultList) Slice() []KCLResult
func (*KCLResultList) Tail ¶
func (p *KCLResultList) Tail() *KCLResult
func (*KCLResultList) ToBool ¶ added in v0.7.2
func (p *KCLResultList) ToBool() (*bool, error)
ToBool returns the result as bool.
func (*KCLResultList) ToFloat64 ¶ added in v0.7.2
func (p *KCLResultList) ToFloat64() (*float64, error)
ToFloat64 returns the result as float64.
func (*KCLResultList) ToInt ¶ added in v0.8.2
func (p *KCLResultList) ToInt() (*int, error)
ToInt returns the result as int.
func (*KCLResultList) ToList ¶ added in v0.7.2
func (p *KCLResultList) ToList() ([]interface{}, error)
ToList returns the result as []interface{}.
func (*KCLResultList) ToMap ¶ added in v0.7.2
func (p *KCLResultList) ToMap() (map[string]interface{}, error)
ToMap returns the result as map[string]interface{}.
func (*KCLResultList) ToString ¶ added in v0.7.2
func (p *KCLResultList) ToString() (string, error)
ToString returns the result as string.
func (*KCLResultList) ToType ¶ added in v0.7.2
func (p *KCLResultList) ToType(target interface{}) error
ToType returns the result as target type.
type Option ¶
type Option struct { *gpyrpc.ExecProgram_Args Err error // contains filtered or unexported fields }
func WithExternalPkgNameAndPath ¶ added in v0.9.2
kcl -E aaa=/xx/xxx/aaa main.k
func WithExternalPkgs ¶
kcl -E aaa=/xx/xxx/aaa main.k
func WithFullTypePath ¶ added in v0.8.0
WithIncludeSchemaTypePath returns a Option which hold a include schema type path switch.
func WithIncludeSchemaTypePath ¶ added in v0.5.4
WithIncludeSchemaTypePath returns a Option which hold a include schema type path switch.
func WithKFilenames ¶
func WithLogger ¶ added in v0.7.0
func WithOverrides ¶
kcl -O pkgpath:path.to.field=field_value kcl -O pkgpath.path.to.field-
func WithPrintOverridesAST ¶
func WithSelectors ¶ added in v0.7.0
kcl -S path.to.field
func WithShowHidden ¶ added in v0.8.0
kcl -H --show_hidden
func WithWorkDir ¶
func (*Option) JSONString ¶
type VersionResult ¶ added in v0.9.2
type VersionResult = gpyrpc.GetVersion_Result
func GetVersion ¶ added in v0.9.2
func GetVersion() (*VersionResult, error)
GetVersion returns the KCL service version information.