TIP: Checkout related projects of this suite
This tool allows to detect all the framework functions used inside a given sh file. The framework functions matches the pattern Namespace::functionName (we can have several namespaces separated by the characters ::). These framework functions will be injected inside a compiled file. The process is recursive so that every framework functions used by imported framework functions will be imported as well (of course only once).
There is the choice between Go template/text or template/html libraries. I chosen template/text to avoid some escaping that are not needed in bash.
Go template/text or template/html don't provide any execution context to the filters (FuncMap).
I'm not using Template.ParseGlob because I have to call it twice to include files of root directory and sub directories with 2 glob patterns. But a bug in text/template makes the template be initialized again after each calls to ParseGlob function. So I compute manually list of templates in internal/render/render.go NewTemplate function.
I simulated a context by pushing the context to the render function. So the data associated to the template has the following structure:
type Context struct {
Template *template.Template
Name string
RootData any
Data any
}
Then each filter has to be called with the right context. The special filter
include
allows to include a sub template overriding context Data.
Template filter functions, internal/render/functions/index.go
includes:
{{ format "${%sLongDescription[@]}" .functionName }}
see Compile command.
This repository uses pre-commit software to ensure every commits respects a set
of rules specified by the .pre-commit-config.yaml
file. It supposes pre-commit
software is installed in your environment.
You also have to execute the following command to enable it:
pre-commit install --hook-type pre-commit --hook-type pre-push
Now each time you commit or push, some linters/compilation tools are launched automatically
Allows to embed files, directories or a framework function. The following syntax can be used:
Syntax: # @embed "srcFile" AS "targetFile"
Syntax: # @embed "srcDir" AS "targetDir"
if @embed
annotation is provided, the file/dir provided will be added inside
the resulting bin file as a tar gz file(base64 encoded) and automatically
extracted when executed.
The compiler's embed annotation offers the ability to embed files or
directories. annotationEmbed
allows to:
Compiler::Embed::extractFile_asName
where asName is the name chosen using
annotation explained above. The original file mode will be restored after
extraction. The variable embed_file_asName
contains the targeted filepath.Compiler::Embed::extractDir_asName
where asName is the name chosen using annotation explained above. The variable
embed_dir_asName contains the targeted directory path.asName
chosen above because path of the temporary directory has been added into the
PATH variable.Formatting is managed exclusively by pre-commit hooks.
build/build-docker.sh
build/build-local.sh
build/test.sh
build/coverage.sh
build/run.sh
build/clean.sh
Compile bin file
go run ./cmd/bash-compiler examples/configReference/shellcheckLint.yaml \
--root-dir /home/wsl/fchastanet/bash-dev-env/vendor/bash-tools-framework \
-t examples/generated -k -d
for debugging purpose, manually Transform and validate yaml file using cue
cue export \
-l input: examples/generated/shellcheckLint-merged.yaml \
internal/model/binFile.cue --out yaml \
-e output >examples/generated/shellcheckLint-cue-transformed.yaml
https://www.kcl-lang.io/docs/user_docs/getting-started/install
cd internal/model/kcl
kcl -D configFile=testsKcl/example.yaml