changeset 11203:8ab76b7c6ff6

added interactive selection capability to 'mx javap' command
author Doug Simon <doug.simon@oracle.com>
date Mon, 05 Aug 2013 14:00:14 +0200
parents 4c0f7b396be6
children f4601ec50637
files mxtool/mx.py
diffstat 1 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mxtool/mx.py	Mon Aug 05 11:24:44 2013 +0200
+++ b/mxtool/mx.py	Mon Aug 05 14:00:14 2013 +0200
@@ -3264,6 +3264,26 @@
                         log(classname)
     return matches
 
+def select_items(candidates):
+    """
+    Presents a command line interface for selecting one or more items from a sequence.
+    """
+    if len(candidates) == 0:
+        return []
+    elif len(candidates) > 1:
+        log('[0] <all>')
+        for i in range(0, len(candidates)):
+            log('[{0}] {1}'.format(i + 1, candidates[i]))
+        s = raw_input('Enter number of selection: ')
+        try:
+            si = int(s)
+        except:
+            si = 0
+        if si == 0 or si not in range(1, len(candidates) + 1):
+            return candidates
+        else:
+            return [candidates[si - 1]]
+
 def javap(args):
     """disassemble classes matching given pattern with javap"""
 
@@ -3271,7 +3291,11 @@
     if not exists(javap):
         abort('The javap executable does not exists: ' + javap)
     else:
-        run([javap, '-private', '-verbose', '-classpath', classpath()] + findclass(args, logToConsole=False))
+        candidates = findclass(args, logToConsole=False)
+        if len(candidates) == 0:
+            log('no matches')
+        selection = select_items(candidates)
+        run([javap, '-private', '-verbose', '-classpath', classpath()] + selection)
 
 def show_projects(args):
     """show all loaded projects"""