Skip to content

Commit

Permalink
gw.py: Remove unnecessary defaults from argparse help texts
Browse files Browse the repository at this point in the history
  • Loading branch information
keirf committed May 15, 2020
1 parent fd2a041 commit 53a348c
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 17 deletions.
3 changes: 1 addition & 2 deletions scripts/greaseweazle/tools/bandwidth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions scripts/greaseweazle/tools/delays.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions scripts/greaseweazle/tools/erase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions scripts/greaseweazle/tools/pin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions scripts/greaseweazle/tools/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions scripts/greaseweazle/tools/reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
5 changes: 2 additions & 3 deletions scripts/greaseweazle/tools/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:])

Expand Down
13 changes: 13 additions & 0 deletions scripts/greaseweazle/tools/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 1 addition & 2 deletions scripts/greaseweazle/tools/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 53a348c

Please sign in to comment.