From 635da7da62fe2102ac6b2574bd91f080b815ed56 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Wed, 2 Apr 2014 23:41:08 +0800 Subject: [PATCH] Renaming check to doctor 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 | 11 +++++---- config-dist.json | 1 + extra/bash_completion | 8 +++--- lib/command.py | 6 +++++ lib/commands/__init__.py | 2 +- lib/commands/{check.py => doctor.py} | 48 +++++++++++++++++++++++++----------- 6 files changed, 51 insertions(+), 25 deletions(-) rename lib/commands/{check.py => doctor.py} (89%) diff --git a/README.md b/README.md index 1056bf0..4608589 100644 --- 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 --- diff --git a/config-dist.json b/config-dist.json index 70b31b5..315d6dd 100644 --- a/config-dist.json +++ b/config-dist.json @@ -203,6 +203,7 @@ // "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" } } diff --git a/extra/bash_completion b/extra/bash_completion index 7e03045..1243327 100644 --- a/extra/bash_completion +++ b/extra/bash_completion @@ -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` diff --git a/lib/command.py b/lib/command.py index 9c7157e..3dbfdc4 100644 --- a/lib/command.py +++ b/lib/command.py @@ -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) diff --git a/lib/commands/__init__.py b/lib/commands/__init__.py index d5b8241..cccce6b 100644 --- a/lib/commands/__init__.py +++ b/lib/commands/__init__.py @@ -33,10 +33,10 @@ commandsList = [ 'backport', 'backup', 'behat', - 'check', 'config', 'create', 'css', + 'doctor', 'fix', 'info', 'init', diff --git a/lib/commands/check.py b/lib/commands/doctor.py similarity index 89% rename from lib/commands/check.py rename to lib/commands/doctor.py index d81bf77..b41f611 100644 --- a/lib/commands/check.py +++ b/lib/commands/doctor.py @@ -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 'Hi' + def remotes(self, args): """Check that the correct remotes are used""" -- 2.11.0