refactor: improve scripts/create.sh
This commit is contained in:
+1
-5
@@ -175,11 +175,7 @@ install() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# @cmd Create a boilplate tool script file.
|
# @cmd Create a boilplate tool script file.
|
||||||
# It automatically generate declaration json for `*.py` and `*.js` and generate `@option` tags for `.sh`.
|
# @arg args~
|
||||||
# Examples:
|
|
||||||
# argc create abc.sh foo bar! baz+ qux*
|
|
||||||
# @arg name! The script filename.
|
|
||||||
# @arg params* The script parameters
|
|
||||||
create() {
|
create() {
|
||||||
./scripts/create.sh "$@"
|
./scripts/create.sh "$@"
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -2,20 +2,27 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
# @describe Create a boilplate tool script file.
|
# @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
|
# @arg params* The script parameters
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
ext="${argc_name##*.}"
|
|
||||||
output="tools/$argc_name"
|
output="tools/$argc_name"
|
||||||
if [[ -f "$output" ]]; then
|
if [[ -f "$output" ]]; then
|
||||||
_die "$output already exists"
|
_die "$output already exists"
|
||||||
fi
|
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
|
case $ext in
|
||||||
sh) create_sh ;;
|
sh) create_sh ;;
|
||||||
js) create_js ;;
|
js) create_js ;;
|
||||||
py) create_py ;;
|
py) create_py ;;
|
||||||
*) _die "Invalid extension name: '$ext'" ;;
|
*) _die "Invalid extension name: $ext, must be one of ${support_exts[*]}" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user