summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorSamuel Walladge <samuel@swalladge.id.au>2017-03-15 10:06:44 +1030
committernfnty <git@nfnty.se>2017-03-15 13:53:03 +0100
commit6b4c87186d42e8ac3f735acc206b07c631be381a (patch)
treecab432e1062d6882d1881d45744d22721cb554da
parent18136950652b4928d71f76e5d47875c263a6e9bd (diff)
downloadranger-6b4c87186d42e8ac3f735acc206b07c631be381a.tar.gz
Improve error message for some commands when called without args
Commands improved:
* `change_mode`
* `flat`
* `chain`
* `chmod`
* All `map` commands
-rwxr-xr-xranger/config/commands.py20
-rw-r--r--ranger/core/actions.py5
2 files changed, 19 insertions, 6 deletions
diff --git a/ranger/config/commands.py b/ranger/config/commands.py
index 6000b504..a2b55126 100755
--- a/ranger/config/commands.py
+++ b/ranger/config/commands.py
@@ -208,6 +208,9 @@ class chain(Command):
     """
 
     def execute(self):
+        if not self.rest(1).strip():
+            self.fm.notify('Syntax: chain <command1>; <command2>; ...', bad=True)
+            return
         for command in [s.strip() for s in self.rest(1).split(";")]:
             self.fm.execute_console(command)
 
@@ -927,6 +930,9 @@ class chmod(Command):
     def execute(self):
         mode_str = self.rest(1)
         if not mode_str:
+            if not self.quantifier:
+                self.fm.notify("Syntax: chmod <octal number>", bad=True)
+                return
             mode_str = str(self.quantifier)
 
         try:
@@ -1180,7 +1186,8 @@ class map_(Command):
 
     def execute(self):
         if not self.arg(1) or not self.arg(2):
-            return self.fm.notify("Not enough arguments", bad=True)
+            self.fm.notify("Syntax: {0} <keysequence> <command>".format(self.get_name()), bad=True)
+            return
 
         self.fm.ui.keymaps.bind(self.context, self.arg(1), self.rest(2))
 
@@ -1455,6 +1462,9 @@ class flat(Command):
             level = int(level_str)
         except ValueError:
             level = self.quantifier
+        if level is None:
+            self.fm.notify("Syntax: flat <level>", bad=True)
+            return
         if level < -1:
             self.fm.notify("Need an integer number (-1, 0, 1, ...)", bad=True)
         self.fm.thisdir.unload()
@@ -1479,8 +1489,8 @@ class stage(Command):
             filelist = [f.path for f in self.fm.thistab.get_selection()]
             try:
                 self.fm.thisdir.vcs.action_add(filelist)
-            except VcsError as error:
-                self.fm.notify('Unable to stage files: {0:s}'.format(str(error)))
+            except VcsError as ex:
+                self.fm.notify('Unable to stage files: {0}'.format(ex))
             self.fm.ui.vcsthread.process(self.fm.thisdir)
         else:
             self.fm.notify('Unable to stage files: Not in repository')
@@ -1500,8 +1510,8 @@ class unstage(Command):
             filelist = [f.path for f in self.fm.thistab.get_selection()]
             try:
                 self.fm.thisdir.vcs.action_reset(filelist)
-            except VcsError as error:
-                self.fm.notify('Unable to unstage files: {0:s}'.format(str(error)))
+            except VcsError as ex:
+                self.fm.notify('Unable to unstage files: {0}'.format(ex))
             self.fm.ui.vcsthread.process(self.fm.thisdir)
         else:
             self.fm.notify('Unable to unstage files: Not in repository')
diff --git a/ranger/core/actions.py b/ranger/core/actions.py
index 703577d3..cf5dc02e 100644
--- a/ranger/core/actions.py
+++ b/ranger/core/actions.py
@@ -74,11 +74,14 @@ class Actions(  # pylint: disable=too-many-instance-attributes,too-many-public-m
         if self.metadata:
             self.metadata.reset()
 
-    def change_mode(self, mode):
+    def change_mode(self, mode=None):
         """:change_mode <mode>
 
         Change mode to "visual" (selection) or "normal" mode.
         """
+        if mode is None:
+            self.fm.notify('Syntax: change_mode <mode>', bad=True)
+            return
         if mode == self.mode:  # pylint: disable=access-member-before-definition
             return
         if mode == 'visual':