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 Jul 27, 2023
1 parent cd8bd90 commit 82c0237
Show file tree
Hide file tree
Showing 14 changed files with 163 additions and 37 deletions.
29 changes: 15 additions & 14 deletions .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.0.2
_commit: v2.1.1
_src_path: gh:kc-workspace/asdf-plugin-template.git
addon_yaml:
archive: true
Expand All @@ -26,21 +26,8 @@ archive_enabled: false
checksum_conf_algorithm: 512
checksum_enabled: true
checksum_url: https://github.com/mikefarah/yq/releases/download/v{version}/checksums
custom_arch_enabled: true
custom_arch_yaml:
aarch64*: arm64
armv5*: arm
armv6*: arm
armv7*: arm
i386: '386'
i686: '386'
powerpc64le: ppc64le
ppc64le: ppc64le
x86: '386'
x86_64: amd64
custom_bin_paths: bin
custom_non_stable_version: (-src|-dev|-latest|-stm|[-\.]rc|-alpha|-beta|[-\.]pre|-next|snapshot|master)
custom_os_enabled: false
custom_require_commands: ''
download_url: https://github.com/mikefarah/yq/releases/download/v{version}/yq_{os}_{arch}
gpg_enabled: false
Expand All @@ -54,6 +41,20 @@ plugin_name: asdf-yq
plugin_org: kc-workspace
plugin_repo: https://github.com/kc-workspace/asdf-yq.git
source_enabled: false
sys_arch_enabled: true
sys_arch_yaml:
aarch64*: arm64
armv5*: armv5
armv6*: armv6
armv7*: armv7
i386: '386'
i686: '386'
powerpc64le: ppc64le
ppc64le: ppc64le
x86: '386'
x86_64: amd64
sys_ext_enabled: false
sys_os_enabled: false
test_cmd_args: --version
version_file_enabled: false
version_prefix: v
21 changes: 21 additions & 0 deletions .github/linters/.gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
title = "gitleaks config"

[extend]
# useDefault will extend the base configuration with the default gitleaks config:
# https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml
useDefault = true

[allowlist]
description = "global allow lists"
paths = [
'''gitleaks.toml''',
'''(.*?)(jpg|gif|doc|docx|zip|xls|pdf|bin|svg|socket|vsidx|v2|suo|wsuo|.dll|pdb|exe)$''',
'''(go.mod|go.sum)$''',
'''gradle.lockfile''',
'''node_modules''',
'''package-lock.json''',
'''pnpm-lock.yaml''',
'''Database.refactorlog''',
'''vendor''',
'''.copier-answers.yml''',
]
39 changes: 39 additions & 0 deletions .github/linters/.markdown-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
###########################
###########################
## Markdown Linter rules ##
###########################
###########################

# Linter rules doc:
# - https://github.com/DavidAnson/markdownlint
# Linter template:
# - https://github.com/super-linter/super-linter/blob/main/TEMPLATES/.markdown-lint.yml
#
# Note:
# To comment out a single error:
# <!-- markdownlint-disable -->
# any violations you want
# <!-- markdownlint-restore -->
#

###############
# Rules by id #
###############
MD004: false # Unordered list style
MD007:
indent: 2 # Unordered list indentation
MD013:
line_length: 400 # Line length 80 is far to short
MD024:
siblings_only: true # Only check sibling headings
MD026:
punctuation: ".,;:!。,;:" # List of not allowed
MD029: false # Ordered list item prefix
MD033: false # Allow inline HTML
MD036: false # Emphasis used instead of a heading

#################
# Rules by tags #
#################
blank_lines: false # Error on blank lines
2 changes: 2 additions & 0 deletions .github/linters/cspell-default.dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ kcws
mergify
envops
venv
keyid
kwargs
60 changes: 52 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ Thank you for investing your time in contributing to our project!
## -----------------------
## Customization functions

kc_asdf_main() {
return 0
}
# kc_asdf_main() {
# local ns="$1"
# shift
#
# return 0
# }

## -----------------------

Expand Down Expand Up @@ -57,6 +60,7 @@ This listed custom function that can defined on any bin/* scripts.
```bash
## Example code of kc_asdf_main function
kc_asdf_main() {
local ns="$1"
return 0
}
```
Expand Down Expand Up @@ -84,7 +88,16 @@ _kc_asdf_custom_arch() {
}
```

3. To custom environment variables, use `_kc_asdf_custom_env()`
3. To custom download extension, use `_kc_asdf_custom_ext()`

```bash
_kc_asdf_custom_ext() {
local ext="$1"
printf "%s" "$ext"
}
```

4. To custom environment variables, use `_kc_asdf_custom_env()`

```bash
## If this return error, it will only log warning message
Expand All @@ -96,7 +109,7 @@ _kc_asdf_custom_env() {
}
```

4. To custom enable-disable features, use `_kc_asdf_custom_enabled_features()`
5. To custom enable-disable features, use `_kc_asdf_custom_enabled_features()`

```bash
## If this return error, mean that feature is disabled
Expand All @@ -107,6 +120,17 @@ _kc_asdf_custom_enabled_features() {
}
```

1. To custom how applications list version, use `_kc_asdf_custom_tags()`

```bash
## Each version should separated by newline
_kc_asdf_custom_tags() {
echo 'v1.1.1'
echo 'v1.1.2'
echo 'v1.1.3'
}
```

## List all callback

1. To filter value from list, use `_kc_asdf_custom_filter()`.
Expand Down Expand Up @@ -177,7 +201,27 @@ _kc_asdf_custom_gpg_filepath() {
}
```

5. To support custom source URL, use `_kc_asdf_custom_source_url()`
5. To support custom setup before run gpg, use `_kc_asdf_custom_gpg_setup()`

```bash
## If this function return error
## we will assume gpg failed
_kc_asdf_custom_gpg_setup() {
local filepath="$1"
return 0
}
```

6. To support custom signature path, use `_kc_asdf_custom_gpg_sigpath()`

```bash
_kc_asdf_custom_gpg_sigpath() {
local dirpath="$1" filename="$2"
printf "%s/%s" "$dirpath" "custom.sig"
}
```

7. To support custom source URL, use `_kc_asdf_custom_source_url()`

```bash
## printf empty string will indicate there are a problem
Expand All @@ -187,7 +231,7 @@ _kc_asdf_custom_source_url() {
}
```

6. To support download source code, use `_kc_asdf_custom_download_source()`
8. To support download source code, use `_kc_asdf_custom_download_source()`

```bash
## This will required _kc_asdf_install_source to defined too
Expand All @@ -198,7 +242,7 @@ _kc_asdf_custom_download_source() {
}
```

7. To support action after downloaded, use `_kc_asdf_custom_post_download()`
9. To support action after downloaded, use `_kc_asdf_custom_post_download()`

```bash
## type can be either 'version' or 'ref'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ contains several extra features for every user including all below.
- `$ASDF_NO_CHECK=<any-string>` to disable pre-check features (e.g. check-cmd)
- `$ASDF_OVERRIDE_OS=<os>` to override os name
- `$ASDF_OVERRIDE_ARCH=<arch>` to override arch name
- `$ASDF_OVERRIDE_EXT=<ext>` to override download extension
- `$GITHUB_TOKEN=<token>` to pass GitHub token on http request
- `$ASDF_LOG_FORMAT=<format>` to custom log format, there are several variables
- **{datetime}** - for current datetime
Expand Down
4 changes: 2 additions & 2 deletions lib/addon/archive.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
## usage: `kc_asdf_archive_extract /tmp/file.tar.gz /tmp/file [internal/path]`
kc_asdf_archive_extract() {
local ns="extract.archive"
local input="$1" output="$2" internal="$3" tmppath
local input="$1" output="$2" internal="${3:-}" tmppath
local ext="${input##*.}"

if [ -n "$internal" ]; then
Expand All @@ -20,7 +20,7 @@ kc_asdf_archive_extract() {
kc_asdf_exec tar -xzf \
"$input" \
-C "$tmppath" \
--strip-components "0" ||
--strip-components "" ||
return 1
fi

Expand Down
10 changes: 5 additions & 5 deletions lib/addon/system.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ kc_asdf_get_os() {

if command -v _kc_asdf_custom_os >/dev/null; then
local tmp="$os"
os="$(_kc_asdf_custom_os "$os")"
os="$(_kc_asdf_custom_os "$tmp")"
kc_asdf_debug "$ns" "developer has custom OS name from %s to %s" "$tmp" "$os"
fi

Expand Down Expand Up @@ -59,13 +59,13 @@ kc_asdf_get_arch() {
arch="arm64"
;;
armv5*)
arch="arm"
arch="armv5"
;;
armv6*)
arch="arm"
arch="armv6"
;;
armv7*)
arch="arm"
arch="armv7"
;;
i386)
arch="386"
Expand All @@ -89,7 +89,7 @@ kc_asdf_get_arch() {

if command -v _kc_asdf_custom_arch >/dev/null; then
local tmp="$arch"
arch="$(_kc_asdf_custom_arch "$arch")"
arch="$(_kc_asdf_custom_arch "$tmp")"
kc_asdf_debug "$ns" "developer has custom ARCH name from %s to %s" "$tmp" "$arch"
fi

Expand Down
14 changes: 13 additions & 1 deletion lib/addon/tags.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,20 @@ kc_asdf_tags_list() {
local ns="tags-list.addon"
local repo="$KC_ASDF_APP_REPO"
local output
output="$(kc_asdf_temp_file)"

if command -v _kc_asdf_custom_tags >/dev/null; then
output="$(kc_asdf_temp_file)"
kc_asdf_debug "$ns" "developer custom list of tags"
_kc_asdf_custom_tags >"$output"
printf "%s" "$output"
return 0
fi

[ -z "$repo" ] &&
kc_asdf_error "$ns" "application didn't contains git repo" &&
return 1

output="$(kc_asdf_temp_file)"
kc_asdf_debug "$ns" "querying from %s" "$repo"
if git ls-remote --tags --refs "$repo" |
grep -o 'refs/tags/.*' |
Expand Down
5 changes: 3 additions & 2 deletions lib/bin/download.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ __asdf_bin() {
local tmpdir tmpfile tmppath
tmpdir="$(kc_asdf_temp_dir)"
local vars=("version=$version")
[ -n "${KC_ASDF_OS:-}" ] && vars+=("os=${KC_ASDF_OS:-}")
[ -n "${KC_ASDF_ARCH:-}" ] && vars+=("arch=${KC_ASDF_ARCH:-}")
[ -n "${KC_ASDF_OS:-}" ] && vars+=("os=$KC_ASDF_OS")
[ -n "${KC_ASDF_ARCH:-}" ] && vars+=("arch=$KC_ASDF_ARCH")
[ -n "${KC_ASDF_EXT:-}" ] && vars+=("ext=$KC_ASDF_EXT")
if command -v kc_asdf_version_parser >/dev/null; then
local major minor patch
read -r major minor patch <<<"$(kc_asdf_version_parser "$version")"
Expand Down
4 changes: 3 additions & 1 deletion lib/bin/help-links.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ __asdf_bin() {
kc_asdf_optional \
kc_asdf_help_header "Links"
__asdf_bin_help_link_printf \
"Application" "$KC_ASDF_APP_REPO"
"Website" "$KC_ASDF_APP_WEBS"
[ -n "$KC_ASDF_APP_REPO" ] && __asdf_bin_help_link_printf \
"Repository" "$KC_ASDF_APP_REPO"
__asdf_bin_help_link_printf \
"Plugin" "$KC_ASDF_REPO"

Expand Down
5 changes: 3 additions & 2 deletions lib/bin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ __asdf_bin() {
"yq:bin/yq"
)
local vars=("version=$version")
[ -n "${KC_ASDF_OS:-}" ] && vars+=("os=${KC_ASDF_OS:-}")
[ -n "${KC_ASDF_ARCH:-}" ] && vars+=("arch=${KC_ASDF_ARCH:-}")
[ -n "${KC_ASDF_OS:-}" ] && vars+=("os=$KC_ASDF_OS")
[ -n "${KC_ASDF_ARCH:-}" ] && vars+=("arch=$KC_ASDF_ARCH")
[ -n "${KC_ASDF_EXT:-}" ] && vars+=("ext=$KC_ASDF_EXT")
if command -v kc_asdf_version_parser >/dev/null; then
local major minor patch
read -r major minor patch <<<"$(kc_asdf_version_parser "$version")"
Expand Down
2 changes: 1 addition & 1 deletion lib/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kc_asdf_debug "$ns" "starting %s with [%s]" \
if command -v kc_asdf_main >/dev/null; then
kc_asdf_debug "$ns" "use main function instead" \
"$KC_ASDF_PLUGIN_ENTRY_NAME"
kc_asdf_main "$@"
kc_asdf_main "${KC_ASDF_PLUGIN_ENTRY_NAME}.bin" "$@"
else
if command -v __asdf_bin >/dev/null; then
__asdf_bin "${KC_ASDF_PLUGIN_ENTRY_NAME}.bin" "$@"
Expand Down
4 changes: 3 additions & 1 deletion lib/common/index.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ export KC_ASDF_ORG KC_ASDF_NAME KC_ASDF_REPO
## Application information
KC_ASDF_APP_TYPE="standalone"
KC_ASDF_APP_NAME="yq"
KC_ASDF_APP_WEBS="https://mikefarah.gitbook.io/yq/"
KC_ASDF_APP_DESC="a portable command-line YAML, JSON, XML, CSV, TOML and properties processor"
KC_ASDF_APP_REPO="https://github.com/mikefarah/yq"
export KC_ASDF_APP_TYPE KC_ASDF_APP_NAME
export KC_ASDF_APP_DESC KC_ASDF_APP_REPO
export KC_ASDF_APP_WEBS KC_ASDF_APP_DESC
export KC_ASDF_APP_REPO

# shellcheck source-path=SCRIPTDIR/internal.sh
source "${KC_ASDF_PLUGIN_PATH:?}/lib/common/internal.sh" || exit 1
Expand Down

0 comments on commit 82c0237

Please sign in to comment.