Skip to content

Commit

Permalink
fix cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden committed May 19, 2024
1 parent d587bb7 commit e702c9c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
20 changes: 15 additions & 5 deletions Argcfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

# @meta dotenv

BIN_DIR="${BIN_DIR:-bin}"
BIN_DIR=bin

LANG_CMDS=( \
"sh:bash" \
Expand Down Expand Up @@ -41,6 +41,7 @@ build-bin() {
_die 'no found functions.txt'
fi
mkdir -p "$BIN_DIR"
rm -rf "$BIN_DIR"/*
names=($(cat functions.txt))
invalid_names=()
for name in "${names[@]}"; do
Expand Down Expand Up @@ -92,19 +93,28 @@ build-declarations-json() {
_die "error: no target functions"
fi
json_list=()
invalid_names=()
not_found_funcs=()
build_failed_funcs=()
for name in "${names[@]}"; do
lang="${name##*.}"
func_file="$lang/$name"
if [[ ! -f "$func_file" ]]; then
not_found_funcs+=("$name")
continue;
fi
json_data="$("build-single-declaration" "$name")"
status=$?
if [ $status -eq 0 ]; then
json_list+=("$json_data")
else
invalid_names+=("$name")
build_failed_funcs+=("$name")
fi
done
if [[ -n "$invalid_names" ]]; then
_die "error: unable to build declaration for: ${invalid_names[*]}"
if [[ -n "$not_found_funcs" ]]; then
_die "error: not found functions: ${not_found_funcs[*]}"
fi
if [[ -n "$build_failed_funcs" ]]; then
_die "error: invalid functions: ${build_failed_funcs[*]}"
fi
echo "Build $argc_output"
echo "["$(IFS=,; echo "${json_list[*]}")"]" | jq '.' > "$argc_output"
Expand Down
7 changes: 6 additions & 1 deletion cmd/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@

function loadModule() {
const path = require("path");
let func_name = process.argv[2];
let func_name = process.argv[1];
if (func_name.endsWith("cmd.js")) {
func_name = process.argv[2]
} else {
func_name = path.basename(func_name)
}
if (!func_name.endsWith(".js")) {
func_name += '.js'
}
Expand Down
7 changes: 6 additions & 1 deletion cmd/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ def load_module(func_name):
print(f"Invalid py function: {func_name}")
sys.exit(1)

func_name = sys.argv[1] if len(sys.argv) > 1 else None
func_name = sys.argv[0]
if func_name.endswith("cmd.py"):
func_name = sys.argv[1]
else:
func_name = os.path.basename(func_name)

if not func_name.endswith(".py"):
func_name += ".py"

Expand Down
7 changes: 6 additions & 1 deletion cmd/cmd.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
require 'pathname'

def load_module
func_name = ARGV[0]
if __FILE__.end_with?("cmd.rb")
func_name = ARGV[0]
else
func_name = Pathname.new(__FILE__).basename.to_s
end

func_name += '.rb' unless func_name.end_with?('.rb')
func_path = File.expand_path("../rb/#{func_name}", __dir__)

Expand Down

0 comments on commit e702c9c

Please sign in to comment.