Skip to content

Commit

Permalink
Merge branch 'shell_function_support' of https://github.com/rayx/argp…
Browse files Browse the repository at this point in the history
  • Loading branch information
nhoffman committed Apr 28, 2024
2 parents 668f0cf + 8ced5d2 commit 88288eb
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions argparse.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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" <<EOF
from __future__ import print_function
import sys
Expand All @@ -27,7 +32,7 @@ class MyArgumentParser(argparse.ArgumentParser):
super(MyArgumentParser, self).print_help(file=file)
sys.exit(1)
parser = MyArgumentParser(prog=os.path.basename("$0"),
parser = MyArgumentParser(prog=os.path.basename("$cmd"),
# preserve newlines in description
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""$ARGPARSE_DESCRIPTION""")
Expand Down

0 comments on commit 88288eb

Please sign in to comment.