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

[tor-commits] [arm/release] Tab completion for interpretor and help commands



commit 48c1888a715209e88c5962f756d40325a6ae28c1
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Sep 15 08:47:31 2011 -0700

    Tab completion for interpretor and help commands
    
    Minor interpretor improvements, mostly adding tab completion for the current
    interpretor commands and anything that will be recognized by '/help'.
---
 src/util/torConfig.py      |   13 +++++++++++++
 src/util/torInterpretor.py |   26 +++++++++++++++++++++-----
 2 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/src/util/torConfig.py b/src/util/torConfig.py
index b2cf345..1d54196 100644
--- a/src/util/torConfig.py
+++ b/src/util/torConfig.py
@@ -321,6 +321,19 @@ def getConfigDescription(option):
   CONFIG_DESCRIPTIONS_LOCK.release()
   return returnVal
 
+def getConfigOptions():
+  """
+  Provides the configuration options from the loaded man page. This is an empty
+  list if no man page has been loaded.
+  """
+  
+  CONFIG_DESCRIPTIONS_LOCK.acquire()
+  
+  returnVal = [CONFIG_DESCRIPTIONS[opt].option for opt in CONFIG_DESCRIPTIONS]
+  
+  CONFIG_DESCRIPTIONS_LOCK.release()
+  return returnVal
+
 def getConfigLocation():
   """
   Provides the location of the torrc, raising an IOError with the reason if the
diff --git a/src/util/torInterpretor.py b/src/util/torInterpretor.py
index 5733f8a..ce28e9c 100644
--- a/src/util/torInterpretor.py
+++ b/src/util/torInterpretor.py
@@ -49,11 +49,11 @@ BACKLOG_LIMIT = 100
 CONTENT_LIMIT = 20000
 
 GENERAL_HELP = """Interpretor commands include:
-  help  - provides information for interpretor and tor commands/config options
-  write - saves backlog to a given location
-  info  - general information for a relay
-  find  - searches backlog for lines with the given regex
-  quit  - shuts down the interpretor
+  /help  - provides information for interpretor and tor commands/config options
+  /write - saves backlog to a given location
+  /info  - general information for a relay
+  /find  - searches backlog for lines with the given regex
+  /quit  - shuts down the interpretor
 
 Tor commands include:
   GETINFO - queries information from tor
@@ -228,6 +228,19 @@ class TorControlCompleter:
     self.commands.append("+LOADCONF") # TODO: another multiline...
     self.commands.append("TAKEOWNERSHIP")
     self.commands.append("QUIT") # TODO: give a confirmation when the user does this?
+    
+    # adds interpretor commands
+    for cmd in INTERPRETOR_HELP:
+      self.commands.append("/" + cmd.lower())
+    
+    # adds help options for the previous commands
+    baseCmd = set([cmd.split(" ")[0].replace("+", "").replace("/", "") for cmd in self.commands])
+    for cmd in baseCmd:
+      self.commands.append("/help " + cmd)
+    
+    # adds /help for tor configuration options
+    for opt in torConfig.getConfigOptions():
+      self.commands.append("/help " + opt)
   
   def getMatches(self, text):
     """
@@ -289,6 +302,9 @@ class ControlInterpretor:
     
     arg = arg.upper()
     
+    # strip slash if someone enters an interpretor command (ex. "/help /help")
+    if arg.startswith("/"): arg = arg[1:]
+    
     if arg:
       if arg in INTERPRETOR_HELP:
         # Provides information for the interpretor argument. This bolds the



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits