Documentation ¶
Overview ¶
Package list extracts information by parsing KCL source code and return it as list. For now, the supported information to be listed will be UpStream/DownStream dependency files. It can also be schemas, schema attributes and so on. Supporting on listing these kinds of information is in the plan.
Index ¶
- Constants
- func FindPkgInfo(workDir string) (pkgroot, pkgpath string, err error)
- func ListDepFiles(workDir string, opt *Option) (files []string, err error)
- func ListDepPackages(workDir string, opt *Option) (pkgs []string, err error)
- func ListDownStreamFiles(workDir string, opt *DepOptions) ([]string, error)
- func ListUpStreamFiles(workDir string, opt *DepOptions) (deps []string, err error)
- type DepOptions
- type DepParser
- func (p *DepParser) GetAppFiles(pkgpath string, includeDependFiles bool) []string
- func (p *DepParser) GetAppPkgs(pkgpath string, includeDependFiles bool) []string
- func (p *DepParser) GetDepPkgList(pkgpath string) []string
- func (p *DepParser) GetError() error
- func (p *DepParser) GetImportMap() map[string][]string
- func (p *DepParser) GetImportMapString() string
- func (p *DepParser) GetKList() []string
- func (p *DepParser) GetMainKList() []string
- func (p *DepParser) GetPkgFileList(pkgpath string) []string
- func (p *DepParser) GetPkgList() []string
- func (p *DepParser) GetTouchedApps(touchedFiles ...string) (touchedApps, untouchedApps []string)
- func (p *DepParser) IsApp(pkgpath string) bool
- type Option
- type SingleAppDepParser
Constants ¶
const ( Default_KclMod = "kcl.mod" Default_KclYaml = "kcl.yaml" Default_ProjectYaml = "project.yaml" )
const KCL_MOD_PATH_ENV = "${KCL_MOD}"
Variables ¶
This section is empty.
Functions ¶
func FindPkgInfo ¶
FindPkgInfo find the pkg information(1. the pkg root 2. the pkg path of current workdir)
func ListDepFiles ¶
ListDepFiles return the depend files from the given path. It will scan and parse the applications within the workdir, then list depend files of the applications.
func ListDepPackages ¶ added in v0.8.4
ListDepPackages return the depend package path from the given path. It will scan and parse the applications within the workdir, then list depend package of the applications.
func ListDownStreamFiles ¶
func ListDownStreamFiles(workDir string, opt *DepOptions) ([]string, error)
ListDownStreamFiles returns a list of DownStream dependent packages/files from the given changed path list. A typical use is to list all the DownStream files when some files changed(added/modified/deleted) in a KCL configuration repository so that certain test cases on those files, instead of all the test cases will need to be rerun to save integration time.
Usage Caution ¶
The implementation of this API is based on reading files in opt.Files so the time-consuming is positively related to the number of files. Do not call the API with high frequency and please ensure at least 10 seconds interval when calling.
Terminology ¶
The word "DownStream" means the dependent direction between two files/packages. One file/package is dependent by its DownStream files/packages if there exist some directly or indirectly import statements in those files/packages that finally import f to them.
Parameters ¶
The "workDir" must be a valid KCL program root directory, otherwise a "pkgroot: not found" error will be produced.
The param opt.Files specifies the scope of the KCL files to be analyzed. Thus only files/packages that have directly or indirectly UpStream/DownStream relations with those files will appears in the result.
The param opt.UpStreams specifies the KCL files to list DownStream files/packages on.
The API will return nil if either opt/opt.Files/opt.UpStreams is nil.
Example ¶
For instance, a KCL program that comes with three files: main.k and base/a.k, base/b.k, and the file main.k contains an import statement that imports base/b.k to it, while the file base/b.k imports base/a.k:
demo (KCL program root) ├── base │ ├── a.k │ └── b.k # import .a └── main.k # import base.b
To list DownStream files/packages of the file base/a.k, the function call will be:
ListDownStreamFiles("demo", &DepOptions{Files:[]string{"main.k"}, UpStreams:[]string{"base/a.k"})
Then the DownStream files/packages of the file base/a.k will be: base/b.k, base and main.k If the import statement in main.k changes to:
import base
Then its DownStream files will be: base, base/a.k and base/b.k And if the import statement in main.k changes to:
import base
And the DownStream files/packages of the file base/a.k stays the same
func ListUpStreamFiles ¶
func ListUpStreamFiles(workDir string, opt *DepOptions) (deps []string, err error)
ListUpStreamFiles returns a list of the UpStream dependent packages/files from the given path list.
Usage Caution ¶
The implementation of this API is based on reading files in opt.Files so the time-consuming is positively related to the number of files. Do not call the API with high frequency and please ensure at least 10 seconds interval when calling.
Terminology ¶
The word "UpStream" means the dependent direction between two files/packages. One file/package (named f) depends on its UpStream files/packages if there exist some directly or indirectly import statements that finally import the UpStream files/packages to f.
Parameters ¶
The "workDir" must be a valid KCL program root directory, otherwise a "pkgroot: not found" error will be produced. The param opt.Files specifies the scope of the KCL files to be analyzed and list UpStream files/packages on. The param opt.UpStreams can be set nil or empty. It will not be used.
The API will return nil if opt or opt.Files is nil.
Example ¶
For instance a KCL program that comes with three files: main.k and base/a.k, base/b.k, and the file main.k contains an import statement that imports base/b.k to it, while the file base/b.k imports base/a.k:
demo (KCL program root) ├── base │ ├── a.k │ └── b.k # import .a └── main.k # import base.b
Then the UpStream files/packages of the file main.k will be: base/a.k and base/b.k If the import statement in main.k changes to:
import base
To list UpStream files/packages of the file main.k, the function call will be:
ListUpStreamFiles("demo", &DepOptions{Files:[]string{"main.k"})
Then its UpStream files/packages will be: base, base/a.k and base/b.k
Types ¶
type DepOptions ¶
type DepOptions struct { // Files defines the scope to inspect the import dependency on. // Each value in the list should be a file or package path relative to the workdir. Files []string // UpStreams defines a list of UpStream file/package paths to ListDownStreamFiles on. // Each value in the list should be a file or package path relative to the workdir. // To list UpStream files/packages, this field will not be used and can be set nil or empty UpStreams []string }
DepOptions provides the files to inspect and list dependencies on
type DepParser ¶
type DepParser struct {
// contains filtered or unexported fields
}
func NewDepParser ¶
func (*DepParser) GetAppFiles ¶
func (*DepParser) GetAppPkgs ¶
func (*DepParser) GetDepPkgList ¶
func (*DepParser) GetImportMap ¶
func (*DepParser) GetImportMapString ¶
func (*DepParser) GetMainKList ¶
func (*DepParser) GetPkgFileList ¶
func (*DepParser) GetPkgList ¶
func (*DepParser) GetTouchedApps ¶
type SingleAppDepParser ¶
type SingleAppDepParser struct {
// contains filtered or unexported fields
}
func NewSingleAppDepParser ¶
func NewSingleAppDepParser(root string, opt ...Option) *SingleAppDepParser
func NewSingleAppDepParserWithFS ¶
func NewSingleAppDepParserWithFS(vfs fs.FS, opts ...Option) *SingleAppDepParser
func (*SingleAppDepParser) GetAppFiles ¶
func (p *SingleAppDepParser) GetAppFiles(appPkgpath string, includeDependFiles bool) ([]string, error)
func (*SingleAppDepParser) GetAppPkgs ¶
func (p *SingleAppDepParser) GetAppPkgs(appPkgpath string, includeDependFiles bool) ([]string, error)