From 7167ce41b61d2ba2cdb526777a4233eb84a3b66a Mon Sep 17 00:00:00 2001 From: Unit 193 Date: Sat, 6 Dec 2014 17:33:25 -0500 Subject: Imported Upstream version 2.99.6 --- .../sqlitestudiocli/commands/clicommandhelp.cpp | 86 ++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 SQLiteStudio3/sqlitestudiocli/commands/clicommandhelp.cpp (limited to 'SQLiteStudio3/sqlitestudiocli/commands/clicommandhelp.cpp') diff --git a/SQLiteStudio3/sqlitestudiocli/commands/clicommandhelp.cpp b/SQLiteStudio3/sqlitestudiocli/commands/clicommandhelp.cpp new file mode 100644 index 0000000..7a957c3 --- /dev/null +++ b/SQLiteStudio3/sqlitestudiocli/commands/clicommandhelp.cpp @@ -0,0 +1,86 @@ +#include "clicommandhelp.h" +#include "clicommandfactory.h" +#include "common/utils.h" +#include "cli_config.h" + +void CliCommandHelp::execute() +{ + if (syntax.isArgumentSet(CMD_NAME)) + printHelp(syntax.getArgument(CMD_NAME)); + else + printHelp(); +} + +QString CliCommandHelp::shortHelp() const +{ + return tr("shows this help message"); +} + +QString CliCommandHelp::fullHelp() const +{ + return tr( + "Use %1 to learn about certain commands supported by the command line interface (CLI) of the SQLiteStudio.\n" + "To see list of supported commands, type %2 without any arguments.\n\n" + "When passing name, you can skip special prefix character ('%3').\n\n" + "You can always execute any command with exactly single '--help' option to see help for that command. " + "It's an alternative for typing: %1 ." + ).arg(cmdName("help")).arg(cmdName("help")).arg(CFG_CLI.Console.CommandPrefixChar.get()).arg(cmdName("help")); +} + +void CliCommandHelp::defineSyntax() +{ + syntax.setName("help"); + syntax.addArgument(CMD_NAME, tr("command", "CLI command syntax"), false); +} + +void CliCommandHelp::printHelp(const QString& cmd) +{ + QString cmdStr = cmd.startsWith(".") ? cmd.mid(1) : cmd; + CliCommand* command = CliCommandFactory::getCommand(cmdStr); + if (!command) + { + println(tr("No such command: %1").arg(cmd)); + println(tr("Type '%1' for list of available commands.").arg(cmdName("help"))); + println(""); + return; + } + command->defineSyntax(); + QStringList aliases = command->aliases(); + QString prefix = CFG_CLI.Console.CommandPrefixChar.get(); + + QString msg; + msg += tr("Usage: %1%2").arg(prefix).arg(command->usage(cmdStr)); + msg += "\n"; + if (aliases.size() > 0) + { + if (aliases.contains(cmdStr)) + { + aliases.removeOne(cmdStr); + aliases << command->getName(); + } + + msg += tr("Aliases: %1").arg(prefix + aliases.join(", " + prefix)); + msg += "\n"; + } + msg += "\n"; + msg += command->fullHelp(); + delete command; + + printBox(msg); +} + +void CliCommandHelp::printHelp() +{ + QHash allCommands = CliCommandFactory::getAllCommands(); + QStringList names = allCommands.keys(); + int width = longest(names).size(); + + names.sort(); + QStringList msgList; + foreach (const QString& cmd, names) + { + msgList << (CFG_CLI.Console.CommandPrefixChar.get() + pad(cmd, width, ' ') + " - " + allCommands[cmd]->shortHelp()); + delete allCommands[cmd]; + } + printBox(msgList.join("\n")); +} -- cgit v1.2.3