diff --git a/install.go b/install.go index 74d69c1c..364380c5 100644 --- a/install.go +++ b/install.go @@ -26,11 +26,24 @@ func InstallKclvm(installRoot string) error { os.Setenv("PATH", os.Getenv("PATH")+":"+binPath) // Run KCL CLI to install dependencies. - err = installBin(binPath, "kcl", kclScript, true) - if err != nil { - return err + scripts := map[string][]byte{ + "kcl": kclScript, + "kclvm": kclvmScript, + "kcl-doc": kclDocScript, + "kcl-fmt": kclFmtScript, + "kcl-lint": kclLintScript, + "kcl-plugin": kclPluginScript, + "kcl-test": kclTestScript, + "kcl-vet": kclVetScript, } - err = installBin(binPath, "kclvm", kclvmScript, false) + for n, script := range scripts { + err := installBin(binPath, n, script, false) + if err != nil { + return err + } + } + // Run KCL CLI to install dependencies. + err = installBin(binPath, "kcl", kclScript, true) if err != nil { return err } diff --git a/kclvm_bin.go b/kclvm_bin.go index 12fe7c34..3a8d4533 100644 --- a/kclvm_bin.go +++ b/kclvm_bin.go @@ -9,3 +9,21 @@ var kclScript []byte //go:embed scripts/kclvm var kclvmScript []byte + +//go:embed scripts/kcl-doc +var kclDocScript []byte + +//go:embed scripts/kcl-fmt +var kclFmtScript []byte + +//go:embed scripts/kcl-lint +var kclLintScript []byte + +//go:embed scripts/kcl-plugin +var kclPluginScript []byte + +//go:embed scripts/kcl-test +var kclTestScript []byte + +//go:embed scripts/kcl-vet +var kclVetScript []byte diff --git a/scripts/kcl-doc b/scripts/kcl-doc new file mode 100755 index 00000000..2d66f6f1 --- /dev/null +++ b/scripts/kcl-doc @@ -0,0 +1,28 @@ +#!/bin/sh + +# Stop on error. +set -e + +# python3 path +python3_bin=`which python3` +kclvm_install_dir=$(cd `dirname $0`/..; pwd) +pip_install_done_file="$kclvm_install_dir/lib/site-packages/kclvm.requirements.done.txt" + +# check python3 +if [ -z "$python3_bin" ]; then + echo "python3 not found!" + exit 1 +fi + +# once: pip install +if [ ! -f $pip_install_done_file ]; then + # check python3 version + $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" + # kclvm pip install all libs + $python3_bin -m pip install kclvm --user + echo 'done' > $pip_install_done_file +fi + +export PYTHONPATH=$kclvm_install_dir/lib/site-packages +export KCLVM_CLI_BIN_PATH=$kclvm_install_dir/bin +$python3_bin -m kclvm.tools.docs "$@" diff --git a/scripts/kcl-fmt b/scripts/kcl-fmt new file mode 100755 index 00000000..c083c3ba --- /dev/null +++ b/scripts/kcl-fmt @@ -0,0 +1,28 @@ +#!/bin/sh + +# Stop on error. +set -e + +# python3 path +python3_bin=`which python3` +kclvm_install_dir=$(cd `dirname $0`/..; pwd) +pip_install_done_file="$kclvm_install_dir/lib/site-packages/kclvm.requirements.done.txt" + +# check python3 +if [ -z "$python3_bin" ]; then + echo "python3 not found!" + exit 1 +fi + +# once: pip install +if [ ! -f $pip_install_done_file ]; then + # check python3 version + $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" + # kclvm pip install all libs + $python3_bin -m pip install kclvm --user + echo 'done' > $pip_install_done_file +fi + +export PYTHONPATH=$kclvm_install_dir/lib/site-packages +export KCLVM_CLI_BIN_PATH=$kclvm_install_dir/bin +$python3_bin -m kclvm.tools.format "$@" diff --git a/scripts/kcl-lint b/scripts/kcl-lint new file mode 100755 index 00000000..7d9bd1aa --- /dev/null +++ b/scripts/kcl-lint @@ -0,0 +1,29 @@ +#!/bin/sh + +# Stop on error. +set -e + +# python3 path +python3_bin=`which python3` +kclvm_install_dir=$(cd `dirname $0`/..; pwd) +pip_install_done_file="$kclvm_install_dir/lib/site-packages/kclvm.requirements.done.txt" + +# check python3 +if [ -z "$python3_bin" ]; then + echo "python3 not found!" + exit 1 +fi + +# once: pip install +if [ ! -f $pip_install_done_file ]; then + # check python3 version + $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" + # kclvm pip install all libs + $python3_bin -m pip install kclvm --user + echo 'done' > $pip_install_done_file +fi + +export PYTHONPATH=$kclvm_install_dir/lib/site-packages +export KCLVM_CLI_BIN_PATH=$kclvm_install_dir/bin +$python3_bin -m kclvm.tools.lint "$@" + diff --git a/scripts/kcl-plugin b/scripts/kcl-plugin new file mode 100755 index 00000000..0fade8fa --- /dev/null +++ b/scripts/kcl-plugin @@ -0,0 +1,29 @@ +#!/bin/sh + +# Stop on error. +set -e + +# python3 path +python3_bin=`which python3` +kclvm_install_dir=$(cd `dirname $0`/..; pwd) +pip_install_done_file="$kclvm_install_dir/lib/site-packages/kclvm.requirements.done.txt" + +# check python3 +if [ -z "$python3_bin" ]; then + echo "python3 not found!" + exit 1 +fi + +# once: pip install +if [ ! -f $pip_install_done_file ]; then + # check python3 version + $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" + # kclvm pip install all libs + $python3_bin -m pip install kclvm --user + echo 'done' > $pip_install_done_file +fi + +export PYTHONPATH=$kclvm_install_dir/lib/site-packages +export KCLVM_CLI_BIN_PATH=$kclvm_install_dir/bin +$python3_bin -m kclvm.tools.plugin "$@" + diff --git a/scripts/kcl-test b/scripts/kcl-test new file mode 100755 index 00000000..775a9184 --- /dev/null +++ b/scripts/kcl-test @@ -0,0 +1,9 @@ +#!/bin/sh + +kcl_go_path=$(cd `dirname $0`; pwd)/kcl-go +if [[ ! -f $kcl_go_path ]]; then + echo "kcl-go not found, please check the installation" + exit 1 +fi +export PYTHONPATH='' +$kcl_go_path test "$@" diff --git a/scripts/kcl-vet b/scripts/kcl-vet new file mode 100755 index 00000000..d794d3b4 --- /dev/null +++ b/scripts/kcl-vet @@ -0,0 +1,28 @@ +#!/bin/sh + +# Stop on error. +set -e + +# python3 path +python3_bin=`which python3` +kclvm_install_dir=$(cd `dirname $0`/..; pwd) +pip_install_done_file="$kclvm_install_dir/lib/site-packages/kclvm.requirements.done.txt" + +# check python3 +if [ -z "$python3_bin" ]; then + echo "python3 not found!" + exit 1 +fi + +# once: pip install +if [ ! -f $pip_install_done_file ]; then + # check python3 version + $python3_bin -c "import sys; sys.exit(0) if sys.version_info>=(3,7,3) else (print('please install python 3.7.3+') or sys.exit(1))" + # kclvm pip install all libs + $python3_bin -m pip install kclvm --user + echo 'done' > $pip_install_done_file +fi + +export PYTHONPATH=$kclvm_install_dir/lib/site-packages +export KCLVM_CLI_BIN_PATH=$kclvm_install_dir/bin +$python3_bin -m kclvm.tools.validation "$@"