Better way of outputting a variable from info command v0.1
authorFrederic Massart <fred@moodle.com>
Wed, 21 Nov 2012 02:57:57 +0000 (10:57 +0800)
committerFrederic Massart <fred@moodle.com>
Wed, 21 Nov 2012 02:57:57 +0000 (10:57 +0800)
bash_completion
moodle-info.py

index a3713ac..29ed0ac 100644 (file)
@@ -98,7 +98,7 @@ function _moodle() {
                 fi
                 ;;
             info)
-                OPTS="--list"
+                OPTS="--list --var"
                 if [[ "${COMP_CWORD}" == 2 && "$CUR" != -* ]]; then
                     OPTS="$OPTS $($BIN info -ln)"
                 elif [[ "${COMP_CWORD}" == 3 && ("$PREV" == "--list" || "$PREV" == "-l") ]]; then
index 155b494..8d3190a 100755 (executable)
@@ -24,9 +24,8 @@ http://github.com/FMCorz/mdk
 
 import sys
 import argparse
-from lib import workplace, moodle, tools
+from lib import workplace
 from lib.tools import debug
-from lib.config import C
 
 Wp = workplace.Workplace()
 
@@ -36,36 +35,36 @@ parser.add_argument('-l', '--list', action='store_true', help='list the instance
 parser.add_argument('-i', '--integration', action='store_true', help='used with --list, only display integration instances', dest='integration')
 parser.add_argument('-s', '--stable', action='store_true', help='used with --list, only display stable instances', dest='stable')
 parser.add_argument('-n', '--name-only', action='store_true', help='used with --list, only display instances name', dest='nameonly')
+parser.add_argument('-v', '--var', metavar='var', default=None, nargs='?', help='variable to output. Does not work with --list.')
 parser.add_argument('name', metavar='name', default=None, nargs='?', help='name of the instance')
-parser.add_argument('var', metavar='var', default=None, nargs='?', help='variable to output')
 args = parser.parse_args()
 
 # List the instances
 if args.list:
-       if args.integration != False or args.stable != False:
-               l = Wp.list(integration = args.integration, stable = args.stable)
-       else:
-               l = Wp.list()
-       l.sort()
-       for i in l:
-               if not args.nameonly:
-                       M = Wp.get(i)
-                       print '{0:<25}'.format(i), M.get('release')
-               else:
-                       print i
+    if args.integration != False or args.stable != False:
+        l = Wp.list(integration=args.integration, stable=args.stable)
+    else:
+        l = Wp.list()
+    l.sort()
+    for i in l:
+        if not args.nameonly:
+            M = Wp.get(i)
+            print '{0:<25}'.format(i), M.get('release')
+        else:
+            print i
 
 # Loading instance
 else:
-       M = Wp.resolve(args.name)
-       if not M:
-           debug('This is not a Moodle instance')
-           sys.exit(1)
+    M = Wp.resolve(args.name)
+    if not M:
+        debug('This is not a Moodle instance')
+        sys.exit(1)
 
-       # Printing variable
-       if args.var != None:
-               print M.get(args.var)
+    # Printing variable
+    if args.var != None:
+        print M.get(args.var)
 
-       # Printing info
-       else:
-               for key, info in M.info().items():
-                       print '{0:<20}: {1}'.format(key, info)
+    # Printing info
+    else:
+        for key, info in M.info().items():
+            print '{0:<20}: {1}'.format(key, info)