# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 2014-04-29 18:40:42
# Node ID 2d93b74335a23d3f70aeebb138ca6be487239e2c
# Parent  f0f8100968429a31948eb74f53b8dd22b7c7e820

revsetbenchmark: use optparse to retrieve argument

We need more flexibility. For example we'll want to run the benchmark on other
repository.

diff --git a/contrib/revsetbenchmarks.py b/contrib/revsetbenchmarks.py
--- a/contrib/revsetbenchmarks.py
+++ b/contrib/revsetbenchmarks.py
@@ -15,6 +15,10 @@
 
 import sys
 from subprocess import check_call, Popen, CalledProcessError, STDOUT, PIPE
+# cannot use argparse, python 2.7 only
+from optparse import OptionParser
+
+
 
 def check_output(*args, **kwargs):
     kwargs.setdefault('stderr', PIPE)
@@ -65,16 +69,22 @@ def getrevs(spec):
     return [r for r in out.split() if r]
 
 
+parser = OptionParser(usage="usage: %prog [options] <revs>")
+parser.add_option("-f", "--file",
+                  help="read revset from FILE", metavar="FILE")
+
+(options, args) = parser.parse_args()
 
 if len(sys.argv) < 2:
-    print >> sys.stderr, 'usage: %s <revs> [file]' % sys.argv[0]
+    parser.print_help()
     sys.exit(255)
 
-target_rev = sys.argv[1]
+
+target_rev = args[0]
 
 revsetsfile = sys.stdin
-if len(sys.argv) > 2:
-    revsetsfile = open(sys.argv[2])
+if options.file:
+    revsetsfile = open(options.file)
 
 revsets = [l.strip() for l in revsetsfile]