Last active
August 24, 2023 01:18
-
-
Save apua/eb08b2c8ffd95e7e8d66845f94897392 to your computer and use it in GitHub Desktop.
shell script with Python argparse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
# Parse arguments | |
# =============== | |
parse_args() { | |
local args=`mktemp` parser=$1; shift | |
python3 -c "$parser" $@ 3>$args | |
args=`cat $args; rm $args` | |
[ "$args" ] || exit | |
eval $args | |
} | |
parse_args ' | |
import argparse, os | |
parser=argparse.ArgumentParser() | |
parser.add_argument("-t", "--test-case", required=True, choices=["IOMMU-22"]) | |
parser.add_argument("-o", "--output", help="output directory") | |
args = parser.parse_args() | |
print(*(f"{k}=\"{v}\"" for k, v in vars(args).items()), file=os.fdopen(3, "w")) | |
' $@ | |
# Init | |
# ==== | |
echo $test_case | |
echo $output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment