refactor: Simplify argparse setup and help handling

This commit is contained in:
n loewen (aider) 2025-06-07 20:15:27 +01:00
parent 0ba3259319
commit 4a780cf193
1 changed files with 5 additions and 6 deletions

11
gtm
View File

@ -369,12 +369,11 @@ def show_help():
parser.print_help()
if __name__ == "__main__":
parser = argparse.ArgumentParser(add_help=False, description="A \"Git Time Machine\" for viewing file history")
parser.add_argument("-d, --diff", action="store_true", help="Highlight newly added and deleted lines")
parser = argparse.ArgumentParser(description="A \"Git Time Machine\" for viewing file history")
parser.add_argument("-d", "--diff", action="store_true", help="Highlight newly added and deleted lines")
parser.add_argument("--diff-additions", action="store_true", help="Highlight newly added lines in green")
parser.add_argument("--diff-deletions", action="store_true", help="Show deleted lines in red")
parser.add_argument("-v", "--version", action="store_true", help="Show version number")
parser.add_argument("-h", "--help", action="store_true", help="Show help information")
parser.add_argument("filename", nargs="?", help="File to view history for")
args = parser.parse_args()
@ -382,9 +381,9 @@ if __name__ == "__main__":
if args.version:
print(f"gtm version {VERSION}")
sys.exit(0)
elif args.help or not args.filename:
show_help()
sys.exit(0 if args.help else 1)
elif not args.filename:
parser.print_help()
sys.exit(1)
filename = args.filename