Skip to content

Commit

Permalink
perf: update plugin from template [autocommit]
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat committed Aug 22, 2023
1 parent 82c0237 commit 8978c60
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .copier-answers.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ contains several extra features for every user including all below.
- `$ASDF_FORCE_DOWNLOAD=<any-string>` to always download even cache exist
- `$ASDF_INSECURE=<any-string>` to disable security features (e.g. checksum)
- `$ASDF_NO_CHECK=<any-string>` to disable pre-check features (e.g. check-cmd)
- `$ASDF_OVERRIDE_REF_REPO=<repository>` to override git repository URL when install with ref mode
- `$ASDF_OVERRIDE_OS=<os>` to override os name
- `$ASDF_OVERRIDE_ARCH=<arch>` to override arch name
- `$ASDF_OVERRIDE_EXT=<ext>` to override download extension
Expand Down
8 changes: 6 additions & 2 deletions lib/addon/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 5 additions & 1 deletion lib/bin/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" \
Expand Down
33 changes: 33 additions & 0 deletions lib/common/defaults.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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' '<input>' '<output>'`
kc_asdf_transfer() {
Expand Down Expand Up @@ -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
}
16 changes: 0 additions & 16 deletions lib/common/internal.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<level>' '<namespace>' '<format>' '<variables>'`
## variables:
Expand Down

0 comments on commit 8978c60

Please sign in to comment.