From 8ced5d2207b4f95ec7f4e5496d53f7458ace7aab Mon Sep 17 00:00:00 2001 From: Huan Xiong Date: Sat, 19 Jan 2019 22:43:06 +0800 Subject: [PATCH] Print function name when using argparse() with shell functions When using argparse() to parse arguments of a shell function, it printed "bash", instead of function name, in usage message. The change fixes it. --- argparse.bash | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/argparse.bash b/argparse.bash index 25f935e..2f273cf 100755 --- a/argparse.bash +++ b/argparse.bash @@ -13,7 +13,12 @@ # MIT License - Copyright (c) 2015 Noah Hoffman argparse(){ - argparser=$(mktemp 2>/dev/null || mktemp -t argparser) + local cmd=${FUNCNAME[1]} + if [[ $cmd == "main" ]]; then + cmd=$0 + fi + + local argparser=$(mktemp 2>/dev/null || mktemp -t argparser) cat > "$argparser" <