From 395f6e702066b65f05c45d2b92cd4baab3dd62cb Mon Sep 17 00:00:00 2001 From: Keisuke Kuroyanagi <ksk@google.com> Date: Sat, 8 Nov 2014 06:24:03 +0900 Subject: [PATCH] Implement help command for dicttoolkit. Bug: 10059681 Change-Id: I0cadf1f80103136cdac5c00b6fca4d81b4bf7384 --- .../src/command_executors/diff_executor.cpp | 6 +++++ .../src/command_executors/diff_executor.h | 1 + .../src/command_executors/header_executor.cpp | 6 +++++ .../src/command_executors/header_executor.h | 1 + .../src/command_executors/help_executor.cpp | 22 ++++++++++++++++++- .../src/command_executors/help_executor.h | 1 + .../src/command_executors/info_executor.cpp | 6 +++++ .../src/command_executors/info_executor.h | 1 + .../command_executors/makedict_executor.cpp | 8 +++++++ .../src/command_executors/makedict_executor.h | 1 + 10 files changed, 52 insertions(+), 1 deletion(-) diff --git a/native/dicttoolkit/src/command_executors/diff_executor.cpp b/native/dicttoolkit/src/command_executors/diff_executor.cpp index 1fe90a9f63..077a40090b 100644 --- a/native/dicttoolkit/src/command_executors/diff_executor.cpp +++ b/native/dicttoolkit/src/command_executors/diff_executor.cpp @@ -28,5 +28,11 @@ const char *const DiffExecutor::COMMAND_NAME = "diff"; return 0; } +/* static */ void DiffExecutor::printUsage() { + printf("*** %s\n", COMMAND_NAME); + printf("Usage: %s\n", COMMAND_NAME); + printf("Shows differences between two dictionaries.\n\n"); +} + } // namespace dicttoolkit } // namespace latinime diff --git a/native/dicttoolkit/src/command_executors/diff_executor.h b/native/dicttoolkit/src/command_executors/diff_executor.h index 5b4e9e609a..fc8dc0d8f3 100644 --- a/native/dicttoolkit/src/command_executors/diff_executor.h +++ b/native/dicttoolkit/src/command_executors/diff_executor.h @@ -27,6 +27,7 @@ class DiffExecutor final { static const char *const COMMAND_NAME; static int run(const int argc, char **argv); + static void printUsage(); private: DISALLOW_IMPLICIT_CONSTRUCTORS(DiffExecutor); diff --git a/native/dicttoolkit/src/command_executors/header_executor.cpp b/native/dicttoolkit/src/command_executors/header_executor.cpp index ec2ca8119d..068a62c311 100644 --- a/native/dicttoolkit/src/command_executors/header_executor.cpp +++ b/native/dicttoolkit/src/command_executors/header_executor.cpp @@ -28,5 +28,11 @@ const char *const HeaderExecutor::COMMAND_NAME = "header"; return 0; } +/* static */ void HeaderExecutor::printUsage() { + printf("*** %s\n", COMMAND_NAME); + printf("Usage: %s\n", COMMAND_NAME); + printf("Prints the header contents of a dictionary file.\n\n"); +} + } // namespace dicttoolkit } // namespace latinime diff --git a/native/dicttoolkit/src/command_executors/header_executor.h b/native/dicttoolkit/src/command_executors/header_executor.h index b482e6bb65..4cdeb1a999 100644 --- a/native/dicttoolkit/src/command_executors/header_executor.h +++ b/native/dicttoolkit/src/command_executors/header_executor.h @@ -27,6 +27,7 @@ class HeaderExecutor final { static const char *const COMMAND_NAME; static int run(const int argc, char **argv); + static void printUsage(); private: DISALLOW_IMPLICIT_CONSTRUCTORS(HeaderExecutor); diff --git a/native/dicttoolkit/src/command_executors/help_executor.cpp b/native/dicttoolkit/src/command_executors/help_executor.cpp index dba9f79fc5..bd29a5b167 100644 --- a/native/dicttoolkit/src/command_executors/help_executor.cpp +++ b/native/dicttoolkit/src/command_executors/help_executor.cpp @@ -17,6 +17,14 @@ #include "command_executors/help_executor.h" #include <cstdio> +#include <functional> +#include <vector> + +#include "command_executors/diff_executor.h" +#include "command_executors/header_executor.h" +#include "command_executors/info_executor.h" +#include "command_executors/makedict_executor.h" +#include "utils/command_utils.h" namespace latinime { namespace dicttoolkit { @@ -24,9 +32,21 @@ namespace dicttoolkit { const char *const HelpExecutor::COMMAND_NAME = "help"; /* static */ int HelpExecutor::run(const int argc, char **argv) { - fprintf(stderr, "Command '%s' has not been implemented yet.\n", COMMAND_NAME); + printf("Available commands:\n\n"); + const std::vector<std::function<void(void)>> printUsageMethods = {DiffExecutor::printUsage, + HeaderExecutor::printUsage, InfoExecutor::printUsage, MakedictExecutor::printUsage, + printUsage}; + for (const auto &printUsageMethod : printUsageMethods) { + printUsageMethod(); + } return 0; } +/* static */ void HelpExecutor::printUsage() { + printf("*** %s\n", COMMAND_NAME); + printf("Usage: %s\n", COMMAND_NAME); + printf("Show this help list.\n\n"); +} + } // namespace dicttoolkit } // namespace latinime diff --git a/native/dicttoolkit/src/command_executors/help_executor.h b/native/dicttoolkit/src/command_executors/help_executor.h index 245fda9b4b..280610eb9d 100644 --- a/native/dicttoolkit/src/command_executors/help_executor.h +++ b/native/dicttoolkit/src/command_executors/help_executor.h @@ -27,6 +27,7 @@ class HelpExecutor final { static const char *const COMMAND_NAME; static int run(const int argc, char **argv); + static void printUsage(); private: DISALLOW_IMPLICIT_CONSTRUCTORS(HelpExecutor); diff --git a/native/dicttoolkit/src/command_executors/info_executor.cpp b/native/dicttoolkit/src/command_executors/info_executor.cpp index 5c9a6366aa..c4d84cab36 100644 --- a/native/dicttoolkit/src/command_executors/info_executor.cpp +++ b/native/dicttoolkit/src/command_executors/info_executor.cpp @@ -28,5 +28,11 @@ const char *const InfoExecutor::COMMAND_NAME = "info"; return 0; } +/* static */ void InfoExecutor::printUsage() { + printf("*** %s\n", COMMAND_NAME); + printf("Usage: %s\n", COMMAND_NAME); + printf("Prints various information about a dictionary file.\n\n"); +} + } // namespace dicttoolkit } // namespace latinime diff --git a/native/dicttoolkit/src/command_executors/info_executor.h b/native/dicttoolkit/src/command_executors/info_executor.h index b42bc0e8ec..4ffa74fb03 100644 --- a/native/dicttoolkit/src/command_executors/info_executor.h +++ b/native/dicttoolkit/src/command_executors/info_executor.h @@ -27,6 +27,7 @@ class InfoExecutor final { static const char *const COMMAND_NAME; static int run(const int argc, char **argv); + static void printUsage(); private: DISALLOW_IMPLICIT_CONSTRUCTORS(InfoExecutor); diff --git a/native/dicttoolkit/src/command_executors/makedict_executor.cpp b/native/dicttoolkit/src/command_executors/makedict_executor.cpp index 5466a5917e..ea62e3c37c 100644 --- a/native/dicttoolkit/src/command_executors/makedict_executor.cpp +++ b/native/dicttoolkit/src/command_executors/makedict_executor.cpp @@ -28,5 +28,13 @@ const char *const MakedictExecutor::COMMAND_NAME = "makedict"; return 0; } +/* static */ void MakedictExecutor::printUsage() { + printf("*** %s\n", COMMAND_NAME); + printf("Usage: %s\n", COMMAND_NAME); + printf("Converts a source dictionary file to one or several outputs.\n" + "Source can be a binary dictionary file or a combined format file.\n" + "Binary version 2 (Jelly Bean), 4, and combined format outputs are supported.\n\n"); +} + } // namespace dicttoolkit } // namespace latinime diff --git a/native/dicttoolkit/src/command_executors/makedict_executor.h b/native/dicttoolkit/src/command_executors/makedict_executor.h index 466d1f7e28..ae1309f60c 100644 --- a/native/dicttoolkit/src/command_executors/makedict_executor.h +++ b/native/dicttoolkit/src/command_executors/makedict_executor.h @@ -27,6 +27,7 @@ class MakedictExecutor final { static const char *const COMMAND_NAME; static int run(const int argc, char **argv); + static void printUsage(); private: DISALLOW_IMPLICIT_CONSTRUCTORS(MakedictExecutor); -- GitLab