here is my argument parser code
import argparse
from argparse import ArgumentParser
def parse_args() -> argparse.Namespace:
parser = ArgumentParser(prog="t3 res", description="Request or manage lab pool resources.")
parser.add_argument(
"--json-output-file", help="Write the json output to the specified file."
)
parser.add_argument("target", metavar="TARGET", help="IP/Hostname of a RPi attenuator or Sector name")
subparsers = parser.add_subparsers(title="sub-command", dest="sub_command")
ramp_atten_parser = subparsers.add_parser("ramp_atten", help="ramp to given attenuation")
ramp_atten_parser.add_argument("channel", choices=["H", "V", "HV"], help="which channel(s) to set")
ramp_atten_parser.add_argument(
"-t", "--interval", type=float, default=0.5, help="the interval between each step in seconds"
)
unreserve = subparsers.add_parser("un", help="Unreserve pool resource(s).")
unreserve.add_argument("id", help="Resource pool ID (typically given by t3 res res).")
return parser.parse_args()
args = parse_args()
▶ python3 tr.py ramp_atten -h
usage: t3 res [-h] [--json-output-file JSON_OUTPUT_FILE]
TARGET {ramp_atten,un} ...
Request or manage lab pool resources.
positional arguments:
TARGET IP/Hostname of a RPi attenuator or Sector name
options:
-h, --help show this help message and exit
--json-output-file JSON_OUTPUT_FILE
Write the json output to the specified file.
sub-command:
{ramp_atten,un}
ramp_atten ramp to given attenuation
un Unreserve pool resource(s).
but if i use --target
instead of target
it works
▶ python3 tr.py ramp_atten -h
usage: t3 res ramp_atten [-h] [-t INTERVAL] {H,V,HV}
positional arguments:
{H,V,HV} which channel(s) to set
options:
-h, --help show this help message and exit
-t INTERVAL, --interval INTERVAL
the interval between each step in seconds