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

login
register
mail settings
Submitter phabricator
Date Jan. 22, 2018, 8:07 p.m.
Message ID <b8d6e12e19c36e4e6ff56c9a33b9afe4@localhost.localdomain>
Download mbox | patch
Permalink /patch/27031/
State Not Applicable
Headers show

Comments

phabricator - Jan. 22, 2018, 8:07 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG32317f8bbe2a: tests: use argparse in get-with-headers.py (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1920?vs=4961&id=4978

REVISION DETAIL
  https://phab.mercurial-scm.org/D1920

AFFECTED FILES
  tests/get-with-headers.py

CHANGE DETAILS




To: indygreg, #hg-reviewers, lothiraldan, durin42
Cc: durin42, lothiraldan, mercurial-devel

Patch

diff --git a/tests/get-with-headers.py b/tests/get-with-headers.py
--- a/tests/get-with-headers.py
+++ b/tests/get-with-headers.py
@@ -5,6 +5,7 @@ 
 
 from __future__ import absolute_import, print_function
 
+import argparse
 import json
 import os
 import sys
@@ -22,25 +23,21 @@ 
 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='*')
 
-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,9 +80,9 @@ 
 
     return response.status
 
-status = request(sys.argv[1], sys.argv[2], sys.argv[3:])
+status = request(args.host, args.path, args.show)
 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)