Skip to content
Snippets Groups Projects
Commit 32317f8b authored by Gregory Szorc's avatar Gregory Szorc
Browse files

tests: use argparse in get-with-headers.py

I'm about to add another flag and I don't want to deal with this
organic, artisanal argument parser.

Differential Revision: https://phab.mercurial-scm.org/D1920
parent eefabd9e
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
from __future__ import absolute_import, print_function
import argparse
import json
import os
import sys
......@@ -22,16 +23,12 @@
except ImportError:
pass
twice = False
if '--twice' in sys.argv:
sys.argv.remove('--twice')
twice = True
headeronly = False
if '--headeronly' in sys.argv:
sys.argv.remove('--headeronly')
headeronly = True
formatjson = False
if '--json' in sys.argv:
sys.argv.remove('--json')
formatjson = True
parser = argparse.ArgumentParser()
parser.add_argument('--twice', action='store_true')
parser.add_argument('--headeronly', action='store_true')
parser.add_argument('--json', action='store_true')
parser.add_argument('--hgproto')
parser.add_argument('host')
parser.add_argument('path')
parser.add_argument('show', nargs='*')
......@@ -37,10 +34,10 @@
hgproto = None
if '--hgproto' in sys.argv:
idx = sys.argv.index('--hgproto')
hgproto = sys.argv[idx + 1]
sys.argv.pop(idx)
sys.argv.pop(idx)
args = parser.parse_args()
twice = args.twice
headeronly = args.headeronly
formatjson = args.json
hgproto = args.hgproto
tag = None
def request(host, path, show):
......@@ -83,5 +80,5 @@
return response.status
status = request(sys.argv[1], sys.argv[2], sys.argv[3:])
status = request(args.host, args.path, args.show)
if twice:
......@@ -87,5 +84,5 @@
if twice:
status = request(sys.argv[1], sys.argv[2], sys.argv[3:])
status = request(args.host, args.path, args.show)
if 200 <= status <= 305:
sys.exit(0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment