Renaming check to doctor
authorFrederic Massart <fmcell@gmail.com>
Wed, 2 Apr 2014 15:41:08 +0000 (23:41 +0800)
committerFrederic Massart <fmcell@gmail.com>
Wed, 2 Apr 2014 15:42:10 +0000 (23:42 +0800)
For backwards compatibility, an alias 'check' has been added to the
default configuration file. Also, now doctor requires an argument
and does not default on all checks.

README.md
config-dist.json
extra/bash_completion
lib/command.py
lib/commands/__init__.py
lib/commands/doctor.py [moved from lib/commands/check.py with 89% similarity]

index 1056bf0..4608589 100644 (file)
--- a/README.md
+++ b/README.md
@@ -139,11 +139,6 @@ Get the instance ready for acceptance testing (Behat), and run the test feature(
     mdk behat -r --tags=@core_completion
 
 
-check
------
-
-Perform some checks on the environment to identify possible problems, and attempt to fix them automatically.
-
 create
 ------
 
@@ -187,6 +182,12 @@ Compile the LESS files from Bootstrapbase
     mdk css --compile
 
 
+doctor
+-----
+
+Perform some checks on the environment to identify possible problems, and attempt to fix them automatically.
+
+
 fix
 ---
 
index 70b31b5..315d6dd 100644 (file)
     //   "upall": "update --all". `mdk upall` will execute `mdk update --all`
     //   "ls": "!ls -al". `mdk ls` will execute `ls -al`
     "aliases": {
+        "check": "doctor",
         "list": "info -l"
     }
 }
index 7e03045..1243327 100644 (file)
@@ -49,7 +49,7 @@ function _mdk() {
     if [[ "${COMP_CWORD}" == 1 ]]; then
         # List the commands and aliases.
         # Ignoring these commands on purpose: init
-        OPTS="alias backport backup behat check config create css fix info install phpunit plugin purge pull push rebase remove run tracker uninstall update upgrade"
+        OPTS="alias backport backup behat config create css doctor fix info install phpunit plugin purge pull push rebase remove run tracker uninstall update upgrade"
         OPTS="$OPTS $($BIN alias list 2> /dev/null | cut -d ':' -f 1)"
     else
         # List of options according to the command.
@@ -89,9 +89,6 @@ function _mdk() {
                     OPTS="$OPTS $(_list_instances)"
                 fi
                 ;;
-            check)
-                OPTS="--all --branch --cached --directories --remotes --wwwroot"
-                ;;
             config)
                 if [[ "${COMP_CWORD}" == 2 ]]; then
                     OPTS="flatlist list show set"
@@ -110,6 +107,9 @@ function _mdk() {
             css)
                 OPTS="--compile --debug --sheets --theme --watch"
                 ;;
+            doctor)
+                OPTS="--all --branch --cached --directories --remotes --wwwroot"
+                ;;
             fix)
                 if [[ "$PREV" == "-n" || "$PREV" == "--name" ]]; then
                     OPTS=`$BIN info -ln`
index 9c7157e..3dbfdc4 100644 (file)
@@ -133,8 +133,14 @@ class CommandRunner(object):
                     for subargument in sub[1]:
                         sargs = subargument[0]
                         skwargs = subargument[1]
+                        if skwargs.has_key('silent'):
+                            del skwargs['silent']
+                            skwargs['help'] = argparse.SUPPRESS
                         subparser.add_argument(*sargs, **skwargs)
             else:
+                if kwargs.has_key('silent'):
+                    del kwargs['silent']
+                    kwargs['help'] = argparse.SUPPRESS
                 parser.add_argument(*args, **kwargs)
         args = parser.parse_args(sysargs)
 
index d5b8241..cccce6b 100644 (file)
@@ -33,10 +33,10 @@ commandsList = [
     'backport',
     'backup',
     'behat',
-    'check',
     'config',
     'create',
     'css',
+    'doctor',
     'fix',
     'info',
     'init',
similarity index 89%
rename from lib/commands/check.py
rename to lib/commands/doctor.py
index d81bf77..b41f611 100644 (file)
@@ -29,7 +29,7 @@ from lib.command import Command
 from lib.tools import mkdir
 
 
-class CheckCommand(Command):
+class DoctorCommand(Command):
 
     _arguments = [
         (
@@ -43,7 +43,7 @@ class CheckCommand(Command):
             ['--all'],
             {
                 'action': 'store_true',
-                'help': 'Enable all the checks, this is the default'
+                'help': 'Enable all the checks'
             }
         ),
         (
@@ -52,7 +52,6 @@ class CheckCommand(Command):
                 'action': 'store_true',
                 'help': 'Check the branch checked out on your integration instances'
             }
-
         ),
         (
             ['--cached'],
@@ -60,7 +59,6 @@ class CheckCommand(Command):
                 'action': 'store_true',
                 'help': 'Check the cached repositories'
             }
-
         ),
         (
             ['--directories'],
@@ -68,7 +66,14 @@ class CheckCommand(Command):
                 'action': 'store_true',
                 'help': 'Check the directories set in the config file'
             }
-
+        ),
+        (
+            ['--hi'],
+            {
+                'action': 'store_true',
+                'help': 'What you see it totally unrelated to what you get',
+                'silent': True
+            }
         ),
         (
             ['--remotes'],
@@ -76,7 +81,6 @@ class CheckCommand(Command):
                 'action': 'store_true',
                 'help': 'Check the remotes of your instances'
             }
-
         ),
         (
             ['--wwwroot'],
@@ -84,21 +88,19 @@ class CheckCommand(Command):
                 'action': 'store_true',
                 'help': 'Check the $CFG->wwwroot of your instances'
             }
-
         )
     ]
     _description = 'Perform several checks on your current installation'
 
     def run(self, args):
 
-        allChecks = True
-        if not args.all:
-            argsDict = vars(args)
-            commands = ['directories', 'cached', 'remotes', 'wwwroot', 'branch']
-            for i in commands:
-                if argsDict.get(i):
-                    allChecks = False
-                    break
+        optionsCount = sum([1 for k, v in vars(args).items() if v != False])
+        if optionsCount == 0 or (optionsCount == 1 and args.fix):
+            self.argumentError('You should probably tell me what symptoms you are experiencing')
+
+        allChecks = False
+        if args.all:
+            allChecks = True
 
         # Check directories
         if args.directories or allChecks:
@@ -120,6 +122,10 @@ class CheckCommand(Command):
         if args.branch or allChecks:
             self.branch(args)
 
+        # Check what you see is what you get
+        if args.hi:
+            self.hi(args)
+
     def branch(self, args):
         """Make sure the correct branch is checked out. Only on integration branches."""
 
@@ -198,6 +204,18 @@ class CheckCommand(Command):
                     print '    Creating %s' % d
                     mkdir(d, 0777)
 
+    def hi(self, args):
+        """I wonder what is the purpose of this...
+
+            hint #1: 1341
+            hint #2: dobedobedoh
+        """
+
+        if args.fix:
+            print 'The horse is a noble animal'
+        else:
+            print '<em>Hi</em>'
+
     def remotes(self, args):
         """Check that the correct remotes are used"""