diff --git a/scripts/greaseweazle/tools/bandwidth.py b/scripts/greaseweazle/tools/bandwidth.py index a1290ba5..35cb75e9 100644 --- a/scripts/greaseweazle/tools/bandwidth.py +++ b/scripts/greaseweazle/tools/bandwidth.py @@ -41,8 +41,7 @@ def measure_bandwidth(usb, args): def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("device", nargs="?", default="auto", help="serial device") parser.prog += ' ' + argv[1] diff --git a/scripts/greaseweazle/tools/delays.py b/scripts/greaseweazle/tools/delays.py index 6bb772ac..90d5df4e 100644 --- a/scripts/greaseweazle/tools/delays.py +++ b/scripts/greaseweazle/tools/delays.py @@ -14,8 +14,7 @@ def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("--select", type=int, help="delay after drive select (usecs)") parser.add_argument("--step", type=int, diff --git a/scripts/greaseweazle/tools/erase.py b/scripts/greaseweazle/tools/erase.py index 886e4fc6..5f6a6de5 100644 --- a/scripts/greaseweazle/tools/erase.py +++ b/scripts/greaseweazle/tools/erase.py @@ -31,8 +31,7 @@ def erase(usb, args): def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("--drive", type=util.drive_letter, default='A', help="drive to write (A,B,0,1,2)") parser.add_argument("--scyl", type=int, default=0, diff --git a/scripts/greaseweazle/tools/pin.py b/scripts/greaseweazle/tools/pin.py index 246cbf0b..77a2e345 100644 --- a/scripts/greaseweazle/tools/pin.py +++ b/scripts/greaseweazle/tools/pin.py @@ -20,8 +20,7 @@ def level(letter): def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("pin", type=int, help="pin number") parser.add_argument("level", type=level, diff --git a/scripts/greaseweazle/tools/read.py b/scripts/greaseweazle/tools/read.py index 73082ac5..2ec807a5 100644 --- a/scripts/greaseweazle/tools/read.py +++ b/scripts/greaseweazle/tools/read.py @@ -42,8 +42,7 @@ def read_to_image(usb, args, image): def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("--drive", type=util.drive_letter, default='A', help="drive to read (A,B,0,1,2)") parser.add_argument("--revs", type=int, default=3, diff --git a/scripts/greaseweazle/tools/reset.py b/scripts/greaseweazle/tools/reset.py index b9faf2bc..328210c3 100644 --- a/scripts/greaseweazle/tools/reset.py +++ b/scripts/greaseweazle/tools/reset.py @@ -14,8 +14,7 @@ def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("device", nargs="?", default="auto", help="serial device") parser.prog += ' ' + argv[1] diff --git a/scripts/greaseweazle/tools/update.py b/scripts/greaseweazle/tools/update.py index 8327ad41..82e297b1 100644 --- a/scripts/greaseweazle/tools/update.py +++ b/scripts/greaseweazle/tools/update.py @@ -86,14 +86,13 @@ def update_firmware(usb, args): def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("file", nargs="?", default="auto", help="update filename") parser.add_argument("device", nargs="?", default="auto", help="serial device") parser.add_argument("--bootloader", action="store_true", - help="update the bootloader (WARNING: Use with caution!)") + help="update the bootloader (use with caution!)") parser.prog += ' ' + argv[1] args = parser.parse_args(argv[2:]) diff --git a/scripts/greaseweazle/tools/util.py b/scripts/greaseweazle/tools/util.py index f806d816..8a9df448 100644 --- a/scripts/greaseweazle/tools/util.py +++ b/scripts/greaseweazle/tools/util.py @@ -18,6 +18,19 @@ from greaseweazle.image.ipf import IPF +class CmdlineHelpFormatter(argparse.ArgumentDefaultsHelpFormatter): + def _get_help_string(self, action): + help = action.help + if '%no_default' in help: + return help.replace('%no_default', '') + if ('%(default)' in help + or action.default is None + or action.default is False + or action.default is argparse.SUPPRESS): + return help + return help + ' (default: %(default)s)' + + def drive_letter(letter): types = { 'A': (USB.BusType.IBMPC, 0), diff --git a/scripts/greaseweazle/tools/write.py b/scripts/greaseweazle/tools/write.py index dbe85ab8..44132603 100644 --- a/scripts/greaseweazle/tools/write.py +++ b/scripts/greaseweazle/tools/write.py @@ -68,8 +68,7 @@ def write_from_image(usb, args, image): def main(argv): - parser = argparse.ArgumentParser( - formatter_class=argparse.ArgumentDefaultsHelpFormatter) + parser = argparse.ArgumentParser(formatter_class=util.CmdlineHelpFormatter) parser.add_argument("--drive", type=util.drive_letter, default='A', help="drive to write (A,B,0,1,2)") parser.add_argument("--scyl", type=int, default=0,