summaryrefslogtreecommitdiff
path: root/source4/scripting/bin
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2011-07-21 12:30:38 +1000
committerAndrew Tridgell <tridge@samba.org>2011-07-28 15:20:52 +1000
commite79040cc720c18cce11731f5140411b40d7dad68 (patch)
treee8c0fc506258da4a4ab08f04c5ff4e69c7bd996b /source4/scripting/bin
parent1a444004dddbd534a40fb0b1fd6ee72d3c8deea9 (diff)
downloadsamba-e79040cc720c18cce11731f5140411b40d7dad68.tar.gz
samba-e79040cc720c18cce11731f5140411b40d7dad68.tar.bz2
samba-e79040cc720c18cce11731f5140411b40d7dad68.zip
samba-tool: Display usage for main commands and list them alphabetically
This makes the MainCommand class similar to SuperCommand class in netcmd. Signed-off-by: Andrew Tridgell <tridge@samba.org>
Diffstat (limited to 'source4/scripting/bin')
-rwxr-xr-xsource4/scripting/bin/samba-tool66
1 files changed, 35 insertions, 31 deletions
diff --git a/source4/scripting/bin/samba-tool b/source4/scripting/bin/samba-tool
index 9735335af5..f220b82fd9 100755
--- a/source4/scripting/bin/samba-tool
+++ b/source4/scripting/bin/samba-tool
@@ -26,44 +26,48 @@ from samba import netcmd
from samba.netcmd import Command, CommandError, Option
class MainCommand(Command):
- """Main class for samba tool commands"""
-
- commands = {}
-
- def _run(self, myname, command=None, *args):
- if command in self.commands:
- return self.commands[command]._run(command, *args)
-
- print "Syntax: %s <command> [options]" % (myname)
- print "Available commands:"
- for cmd in self.commands:
- print " %-12s - %s" % (cmd, self.commands[cmd].description)
- if command in [None, 'help', '-h', '--help']:
- return 0
- raise CommandError("No such command '%s'" % command)
-
- def usage(self, myname, command=None, *args):
- if command is None or not command in self.commands:
- print "Usage: %s (%s) [options]" % (myname,
- " | ".join(self.commands.keys()))
- else:
- return self.commands[command].usage(*args)
+ """Main class for samba tool commands"""
+
+ commands = {}
+
+ def _run(self, myname, command=None, *args):
+ if command in self.commands:
+ return self.commands[command]._run(command, *args)
+ print "Usage: samba-tool <command> [options]"
+ print "Available commands:"
+ cmds = self.commands.keys()
+ cmds.sort()
+ for cmd in cmds:
+ print " %-16s - %s" % (cmd, self.commands[cmd].description)
+ if command in [None]:
+ raise CommandError("You must specify a command")
+ if command in ['help', '-h', '--help']:
+ print "For more help on a specific command, please type: samba-tool <command> (-h|--help)"
+ return 0
+ raise CommandError("No such command '%s'" % command)
+
+ def usage(self, myname, command=None, *args):
+ if command is None or not command in self.commands:
+ print "Usage: samba-tool %s (%s) [options]" % (myname,
+ " | ".join(self.commands.keys()))
+ else:
+ return self.commands[command].usage(*args)
class cmd_sambatool(MainCommand):
- """Samba Tool Commands"""
- commands = netcmd.commands
+ """Samba Tool Commands"""
+ commands = netcmd.commands
if __name__ == '__main__':
- cmd = cmd_sambatool()
+ cmd = cmd_sambatool()
- command = None
- args = ()
+ command = None
+ args = ()
- if len(sys.argv) > 1:
- command = sys.argv[1]
- if len(sys.argv) > 2:
- args = sys.argv[2:]
+ if len(sys.argv) > 1:
+ command = sys.argv[1]
+ if len(sys.argv) > 2:
+ args = sys.argv[2:]
cmd._run("samba-tool.py", command, *args)