Jelajahi Sumber

Start using argparse.

Jelmer Vernooij 4 tahun lalu
induk
melakukan
79e309324d
1 mengubah file dengan 7 tambahan dan 9 penghapusan
  1. 7 9
      dulwich/cli.py

+ 7 - 9
dulwich/cli.py

@@ -31,6 +31,7 @@ a way to test Dulwich.
 import os
 import sys
 from getopt import getopt
+import argparse
 import optparse
 import signal
 from typing import Dict, Type
@@ -524,15 +525,12 @@ class cmd_pull(Command):
 
 class cmd_push(Command):
 
-    def run(self, args):
-        parser = optparse.OptionParser()
-        options, args = parser.parse_args(args)
-        if len(args) < 2:
-            print("Usage: dulwich push TO-LOCATION REFSPEC..")
-            sys.exit(1)
-        to_location = args[0]
-        refspecs = args[1:]
-        porcelain.push('.', to_location, refspecs)
+    def run(self, argv):
+        parser = argparse.ArgumentParser()
+        parser.add_argument('to_location', type=str)
+        parser.add_argument('refspec', type=str, nargs='*')
+        args = parser.parse_args(argv)
+        porcelain.push('.', args.to_location, args.refspec or None)
 
 
 class cmd_remote_add(Command):