Fixed "be --dir --complete"
authorW. Trevor King <wking@drexel.edu>
Mon, 13 Jul 2009 11:46:58 +0000 (07:46 -0400)
committerW. Trevor King <wking@drexel.edu>
Mon, 13 Jul 2009 11:46:58 +0000 (07:46 -0400)
be
libbe/cmdutil.py

diff --git a/be b/be
index 81d07878577a9aac0986dfcb2b07918b4909470b..657f968f6dd39a27440fecdd96a6e02b7071b126 100755 (executable)
--- a/be
+++ b/be
@@ -37,6 +37,13 @@ parser.add_option("-d", "--dir", dest="dir", metavar="DIR",
 
 try:
     options,args = parser.parse_args()
+    for option,value in cmdutil.option_value_pairs(options, parser):
+        if value == "--complete":
+            if option == "dir":
+                if len(args) == 0:
+                    args = ["."]
+                paths = cmdutil.complete_path(args[0])
+                raise cmdutil.GetCompletions(paths)
 except cmdutil.GetHelp:
     print cmdutil.help(parser=parser)
     sys.exit(0)
index a91b1c7446da41520ac2385166ebd1a819af285e..758924180d9a8c97a2d483ddd5e11da12c3e4db7 100644 (file)
@@ -15,6 +15,7 @@
 #    You should have received a copy of the GNU General Public License
 #    along with this program; if not, write to the Free Software
 #    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+import glob
 import optparse
 import os
 from textwrap import TextWrapper
@@ -187,6 +188,13 @@ def default_complete(options, args, parser, bugid_args={}):
                 raise GetCompletions(bugshortnames)
             raise GetCompletions()
 
+def complete_path(path):
+    """List possible path completions for path."""
+    comps = glob.glob(path+"*") + glob.glob(path+"/*")
+    if len(comps) == 1 and os.path.isdir(comps[0]):
+        comps.extend(glob.glob(comps[0]+"/*"))
+    return comps
+
 def underlined(instring):
     """Produces a version of a string that is underlined with '='