2 # mw - VCS-like nonsense for MediaWiki websites
3 # Copyright (C) 2009 Ian Weller <ian@ianweller.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 self.me = os.path.basename(sys.argv[0])
30 for name in mw.clicommands.__dict__:
31 if name == 'CommandBase':
33 clazz = mw.clicommands.__dict__[name]
34 if isinstance(clazz, type) and \
35 issubclass(clazz, mw.clicommands.CommandBase):
37 self.commands[cmd.name] = cmd
38 self.shortcuts[cmd.name] = cmd.shortcuts
39 self.all_commands = self.commands
40 for command in self.shortcuts:
41 for shortcut in self.shortcuts[command]:
42 self.all_commands[shortcut] = self.commands[command]
45 print 'usage: %s [subcommand]' % self.me
47 for name in self.commands:
48 cmd = self.commands[name]
49 if len(cmd.shortcuts) > 0:
50 full = name + ' (' + ' '.join(cmd.shortcuts) + ')'
53 print("\t%-14s %-25s" % (full, cmd.description))
58 # determine what the subcommand is
60 if sys.argv[1] in self.all_commands:
61 the_command = sys.argv[1] # SWEET ACTION
62 elif sys.argv[1] in ['--help', '-h']:
65 print '%s: invalid subcommand: %s' % (self.me, sys.argv[1])
67 if len(sys.argv) == 1:
70 self.commands[the_command].main()