[osmium-tool] 10/44: Make help output a bit more flexible.

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Tue Jul 21 20:15:54 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to tag v1.1.0
in repository osmium-tool.

commit a5a41e2dc24bfc5a3fe2c70f817860714c46df55
Author: Jochen Topf <jochen at topf.org>
Date:   Tue Apr 21 14:36:36 2015 +0200

    Make help output a bit more flexible.
    
    If the 'man' command can not be executed, a one line help message
    will be printed and the user pointed to the osmcode.org web site.
    This is especially interesting for Windows, because the man page
    is not available there.
---
 src/command_help.cpp | 33 +++++++++++++++++++++++----------
 src/osmc.hpp         |  8 ++++++++
 2 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/src/command_help.cpp b/src/command_help.cpp
index 899118f..8e2bc91 100644
--- a/src/command_help.cpp
+++ b/src/command_help.cpp
@@ -30,9 +30,6 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 #ifndef _MSC_VER
 # include <unistd.h>
-#else
-# include <process.h>
-# define execlp _execlp
 #endif
 
 #include "command_help.hpp"
@@ -42,12 +39,23 @@ bool CommandHelp::setup(const std::vector<std::string>& arguments) {
     return true;
 }
 
+void show_help(const std::string& topic, const std::string& info) {
+#ifndef _MSC_VER
+    // show man page
+    std::string manpage("osmium-");
+    manpage += topic;
+    ::execlp("man", "man", manpage.c_str(), nullptr);
+#endif
+    std::cout << info << "\n";
+    std::cout << "You'll find more documentation at http://osmcode.org/osmium/\n";
+}
+
 bool CommandHelp::run() {
+    auto commands = CommandFactory::help();
+
     if (m_topic == "help") {
         std::cout << "Usage: osmium [--version] [--help] <command> [<args>]\n\nCommands are:\n";
 
-        auto commands = CommandFactory::help();
-
         // find the maximum length of all command names
         size_t max_width = std::accumulate(commands.begin(), commands.end(), size_t(0), [](size_t max_so_far, std::pair<std::string, std::string> info) {
             return std::max(max_so_far, info.first.length());
@@ -62,13 +70,18 @@ bool CommandHelp::run() {
         return true;
     }
 
-    // show man page
-    std::string manpage("osmium-");
-    manpage += m_topic;
-    ::execlp("man", "man", manpage.c_str(), nullptr);
+    std::string description = CommandFactory::get_description(m_topic);
+    if (!description.empty()) {
+        show_help(m_topic, std::string("osmium ") + m_topic + ": " + description);
+        return true;
+    }
 
-    std::cerr << "Executing man command failed: " << std::strerror(errno) << std::endl;
+    if (m_topic == "file-formats") {
+        show_help("file-formats", "osmium file-formats: Supported formats are 'xml', 'pbf', and 'opl'.");
+        return true;
+    }
 
+    std::cerr << "Unknown help topic '" << m_topic << "'\n";
     return false;
 }
 
diff --git a/src/osmc.hpp b/src/osmc.hpp
index 1a55f63..0d26b6a 100644
--- a/src/osmc.hpp
+++ b/src/osmc.hpp
@@ -114,6 +114,14 @@ public:
         return instance().register_command(name, description, create_function);
     }
 
+    static std::string get_description(const std::string& name) {
+        auto it = instance().m_commands.find(name);
+        if (it == instance().m_commands.end()) {
+            return "";
+        }
+        return it->second.description;
+    }
+
     bool register_command(const std::string& name, const std::string& description, create_command_type create_function) {
         command_info info {description, create_function};
         return m_commands.insert(std::make_pair(name, info)).second;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/osmium-tool.git



More information about the Pkg-grass-devel mailing list