Skip to content

Commit

Permalink
feat(download): support custom how to download source code
Browse files Browse the repository at this point in the history
  • Loading branch information
kamontat committed Aug 22, 2023
1 parent 2ec3988 commit b821ca1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
3 changes: 2 additions & 1 deletion copier.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ source_type:
choices:
- git
- archive
- custom
when: "{{ source_enabled }}"

source_url:
Expand All @@ -97,7 +98,7 @@ source_url:
https://example.com/repo/{version}.tar.gz
{%- endif -%}
validator: "{% from pathjoin('macros', 'validators.jinja') import v_https %}{{ v_https(source_url) }}"
when: "{{ source_enabled }}"
when: "{{ source_enabled and source_type != 'custom' }}"

archive_enabled:
type: bool
Expand Down
9 changes: 9 additions & 0 deletions templates/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
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

## 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"

if [ -z "$filename" ]; then
mode="custom"
elif echo "$filename" | grep -qiE "\.git$"; then
mode="git"
{%- if archive_enabled %}

echo "$filename" | grep -qiE "{{ archive_regex }}" &&
elif echo "$filename" | grep -qiE "{{ archive_regex }}"; then
mode="archive"
{%- endif %}
{% if package_enabled -%}
echo "$filename" | grep -qiE "{{ package_regex }}" &&
{%- if package_enabled %}
elif echo "$filename" | grep -qiE "{{ package_regex }}"; then
mode="package"
{% endif -%}

echo "$filename" | grep -qiE "\.git$" &&
mode="git"
{%- endif %}
fi

kc_asdf_debug "$ns" "download mode of %s is %s" \
"$filename" "$mode"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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

0 comments on commit b821ca1

Please sign in to comment.