Skip to content

Commit

Permalink
refactor: improve scripts/create.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed Jun 6, 2024
1 parent c6eeb84 commit f58e9ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
6 changes: 1 addition & 5 deletions Argcfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ install() {
}

# @cmd Create a boilplate tool script file.
# It automatically generate declaration json for `*.py` and `*.js` and generate `@option` tags for `.sh`.
# Examples:
# argc create abc.sh foo bar! baz+ qux*
# @arg name! The script filename.
# @arg params* The script parameters
# @arg args~
create() {
./scripts/create.sh "$@"
}
Expand Down
13 changes: 10 additions & 3 deletions scripts/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,27 @@
set -e

# @describe Create a boilplate tool script file.
# @arg name! The script filename.
# It automatically generate declaration json for `*.py` and `*.js` and generate `@option` tags for `.sh`.
# Examples:
# argc create abc.sh foo bar! baz+ qux*
# @arg name! The script file name.
# @arg params* The script parameters

main() {
ext="${argc_name##*.}"
output="tools/$argc_name"
if [[ -f "$output" ]]; then
_die "$output already exists"
fi
ext="${argc_name##*.}"
support_exts=('.sh' '.js' '.py')
if [[ "$ext" == "$argc_name" ]]; then
_die "No extension name, pelease add one of ${support_exts[*]}"
fi
case $ext in
sh) create_sh ;;
js) create_js ;;
py) create_py ;;
*) _die "Invalid extension name: '$ext'" ;;
*) _die "Invalid extension name: $ext, must be one of ${support_exts[*]}" ;;
esac
}

Expand Down

0 comments on commit f58e9ea

Please sign in to comment.