[meld] Check argument numbers early rather than show an error dialog



commit fc638f76bf5ae5281028a866aac6004710d78a4b
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Wed May 20 09:43:11 2009 +1000

    Check argument numbers early rather than show an error dialog
    
    Rather than showing an error dialog, just raise a command line parser
    error if we get the wrong number of arguments, and make sure that we have
    the right number of leftover arguments before creating tabs from the
    --diff switch. This commit also removes duplicate checking of argument
    numbers for the --diff switch.

 meld/meldapp.py |   24 +++++++-----------------
 1 files changed, 7 insertions(+), 17 deletions(-)
---
diff --git a/meld/meldapp.py b/meld/meldapp.py
index d33248b..ae125b5 100644
--- a/meld/meldapp.py
+++ b/meld/meldapp.py
@@ -824,15 +824,6 @@ class MeldApp(gnomeglade.Component):
     #
     # Usage
     #
-    def usage(self, msg):
-        response = misc.run_dialog(msg,
-            self,
-            gtk.MESSAGE_ERROR,
-            gtk.BUTTONS_NONE,
-            [(gtk.STOCK_QUIT, gtk.RESPONSE_CANCEL), (gtk.STOCK_OK, gtk.RESPONSE_OK)] )
-        if response == gtk.RESPONSE_CANCEL:
-            sys.exit(0)
-
     def usage_msg(self):
         usage_file = "<%s>" % _("file")
         usage_dir = "<%s>" % _("dir")
@@ -883,16 +874,15 @@ class MeldApp(gnomeglade.Component):
                           dest="diff", default=[],
                           help=_("Creates a diff tab for up to 3 supplied files or directories."))
         options, args = parser.parse_args(rawargs)
+        if len(args) > 3:
+            parser.error(_("too many arguments (wanted 0-3, got %d)") % len(args))
+
         for files in options.diff:
-            if len(files) not in (1, 2, 3):
-                self.usage(_("Invalid number of arguments supplied for --diff."))
             self.append_diff(files)
-        if len(args) not in (0, 1, 2, 3):
-            self.usage(_("Wrong number of arguments (Got %i)") % len(args))
-        else:
-            tab = self.open_paths(args, options.auto_compare)
-            if tab:
-                tab.set_labels(options.label)
+
+        tab = self.open_paths(args, options.auto_compare)
+        if tab:
+            tab.set_labels(options.label)
 
     def _single_file_open(self, path):
         doc = vcview.VcView(self.prefs)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]