From 8978c60393cf4282b84127f435cdc58707113a08 Mon Sep 17 00:00:00 2001 From: Kamontat Chantrachirathumrong <14089557+kamontat@users.noreply.github.com> Date: Tue, 22 Aug 2023 19:26:44 +0700 Subject: [PATCH] perf: update plugin from template [autocommit] --- .copier-answers.yml | 2 +- .github/workflows/main.yml | 2 +- CONTRIBUTING.md | 9 +++++++++ README.md | 1 + lib/addon/download.sh | 8 ++++++-- lib/bin/download.sh | 6 +++++- lib/common/defaults.sh | 33 +++++++++++++++++++++++++++++++++ lib/common/internal.sh | 16 ---------------- 8 files changed, 56 insertions(+), 21 deletions(-) diff --git a/.copier-answers.yml b/.copier-answers.yml index c022598..383126e 100644 --- a/.copier-answers.yml +++ b/.copier-answers.yml @@ -1,6 +1,6 @@ --- ## Changes here will be overwritten by Copier; NEVER EDIT MANUALLY -_commit: v2.1.1 +_commit: v2.2.2 _src_path: gh:kc-workspace/asdf-plugin-template.git addon_yaml: archive: true diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 206fd04..b1098b1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -21,7 +21,7 @@ jobs: - name: Checkout source code uses: actions/checkout@v3 - name: Running cspell - uses: streetsidesoftware/cspell-action@v2 + uses: streetsidesoftware/cspell-action@v3 with: config: ".github/linters/cspell.json" # Log progress and other information during the action execution. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d62462f..27cc703 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -254,6 +254,15 @@ _kc_asdf_custom_post_download() { } ``` +10. To support custom download source code, use `_kc_asdf_custom_source_download()` + +```bash +## If you set source mode to custom, this is required +_kc_asdf_custom_source_download() { + local version="$1" output="$2" +} +``` + ## Install callback 1. To support custom build source code, use `_kc_asdf_custom_source_build()` diff --git a/README.md b/README.md index 11090e2..79c9254 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ contains several extra features for every user including all below. - `$ASDF_FORCE_DOWNLOAD=` to always download even cache exist - `$ASDF_INSECURE=` to disable security features (e.g. checksum) - `$ASDF_NO_CHECK=` to disable pre-check features (e.g. check-cmd) +- `$ASDF_OVERRIDE_REF_REPO=` to override git repository URL when install with ref mode - `$ASDF_OVERRIDE_OS=` to override os name - `$ASDF_OVERRIDE_ARCH=` to override arch name - `$ASDF_OVERRIDE_EXT=` to override download extension diff --git a/lib/addon/download.sh b/lib/addon/download.sh index b17e774..f742094 100755 --- a/lib/addon/download.sh +++ b/lib/addon/download.sh @@ -2,13 +2,17 @@ ## Get download mode based on input filename ## usage: `kc_asdf_download_mode 'test.tar.gz'` -## output: git|file|archive|package +## output: git|file|archive|package|custom kc_asdf_download_mode() { local ns="download-mode.addon" local filename="$1" local mode="file" - echo "$filename" | grep -qiE "\.git$" && + + if [ -z "$filename" ]; then + mode="custom" + elif echo "$filename" | grep -qiE "\.git$"; then mode="git" + fi kc_asdf_debug "$ns" "download mode of %s is %s" \ "$filename" "$mode" diff --git a/lib/bin/download.sh b/lib/bin/download.sh index ac37b12..8c5d211 100755 --- a/lib/bin/download.sh +++ b/lib/bin/download.sh @@ -68,7 +68,11 @@ __asdf_bin() { tmpfile="${url##*/}" mode="$(kc_asdf_download_mode "$tmpfile")" kc_asdf_debug "$ns" "download mode is %s" "$mode" - if [[ "$mode" == "git" ]]; then + if [[ "$mode" == "custom" ]]; then + kc_asdf_step "custom" "custom download mode" \ + _kc_asdf_custom_source_download "$version" "$outdir" || + return 1 + elif [[ "$mode" == "git" ]]; then kc_asdf_debug "$ns" "cloning '%s' to '%s'" \ "$url" "$outdir" kc_asdf_step "git-clone" "$url" \ diff --git a/lib/common/defaults.sh b/lib/common/defaults.sh index 8c5c83d..6139bd5 100755 --- a/lib/common/defaults.sh +++ b/lib/common/defaults.sh @@ -97,6 +97,23 @@ kc_asdf_load_addon() { fi } +## Calling bin from another bin +kc_asdf_call_bin() { + local ns="call-bin.defaults" + local name="$1" + shift + + local bin="${KC_ASDF_PLUGIN_PATH:?}/bin/$name" + if [ -f "$bin" ]; then + kc_asdf_debug "$ns" "sourcing %s (%s)" \ + "$name" "$bin" + bash "$bin" "$@" + else + kc_asdf_error "$ns" "file '%s' is missing" "$bin" + return 1 + fi +} + ## Transfer input to output based on input mode ## usage: `kc_adf_transfer 'copy|move|link' '' ''` kc_asdf_transfer() { @@ -222,3 +239,19 @@ kc_asdf_present_dir() { [ -d "$directory" ] && ls -A1q "$directory" | grep -q . } + +## Ensure input commands is available +## e.g. `kc_asdf_commands 'echo'` +kc_asdf_commands() { + local ns="require.internal" + [ -n "${ASDF_NO_CHECK:-}" ] && + kc_asdf_debug "$ns" "\$ASDF_NO_CHECK exist, skipped checking requirement" && + return 0 + + for cmd in "$@"; do + if ! command -v "$cmd" >/dev/null; then + kc_asdf_error "$ns" "missing required command: '%s'" "$cmd" + exit 1 + fi + done +} diff --git a/lib/common/internal.sh b/lib/common/internal.sh index e73070d..b0791e8 100755 --- a/lib/common/internal.sh +++ b/lib/common/internal.sh @@ -28,22 +28,6 @@ __asdf_load() { return "$code" } -## The will exit with error if requirement isn't meet -## e.g. `__asdf_requirement` -__asdf_requirement() { - local ns="require.internal" - [ -n "${ASDF_NO_CHECK:-}" ] && - kc_asdf_debug "$ns" "\$ASDF_NO_CHECK exist, skipped checking requirement" && - return 0 - - for cmd in "$@"; do - if ! command -v "$cmd" >/dev/null; then - kc_asdf_error "$ns" "missing required command: '%s'" "$cmd" - exit 1 - fi - done -} - ## Print log to stderr ## usage: `kc_asdf_log '' '' '' ''` ## variables: