Esempio n. 1
0
parser.add_argument('-l', '--list', action='store_true', help='list the available commands')
parser.add_argument('-v', '--version', action='store_true', help='display the current version')
parser.add_argument('command', metavar='command', nargs='?', help='command to call', choices=choices)
parser.add_argument('args', metavar='arguments', nargs=argparse.REMAINDER, help='arguments of the command')
parsedargs = parser.parse_args()

cmd = parsedargs.command
args = parsedargs.args

# There is no command, what do we do?
if not cmd:
    if parsedargs.version:
        print 'MDK version %s' % __version__
    elif parsedargs.list:
        for c in sorted(commandsList):
            print '{0:<15} {1}'.format(c, getCommand(c)._description)
    else:
        parser.print_help()
    sys.exit(0)

# Looking up for an alias
alias = C.get('aliases.%s' % cmd)
if alias != None:
    if alias.startswith('!'):
        cmd = alias[1:]
        i = 0
        # Replace $1, $2, ... with passed arguments
        for arg in args:
            i += 1
            cmd = cmd.replace('$%d' % i, arg)
        # Remove unknown $[0-9]
Esempio n. 2
0
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.

http://github.com/FMCorz/mdk
"""

import sys
from os.path import basename
from lib.command import CommandRunner
from lib.commands import getCommand
from lib.config import Conf

f = basename(__file__)
sys.stderr.write("Do not call %s directly.\n" % (f))
sys.stderr.write("This file will be removed in a later version.\n")
sys.stderr.write("Please use `mdk [command] [arguments]`\n")
sys.stderr.write("\n")

cmd = f.replace('moodle-', '').replace('.py', '')
cls = getCommand(cmd)
Cmd = cls(Conf())
Runner = CommandRunner(Cmd)
Runner.run(None, prog='%s %s' % ('mdk', cmd))