[osmium-tool] 37/44: Move handling of common cmd line options into common functions.

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Tue Jul 21 20:15:57 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 3dd0ceac2721f8abcfd0d43f3823b61b66c0ce4c
Author: Jochen Topf <jochen at topf.org>
Date:   Fri Jul 3 14:32:40 2015 +0200

    Move handling of common cmd line options into common functions.
---
 src/command_apply_changes.cpp | 13 +++++--------
 src/command_cat.cpp           | 11 ++++-------
 src/command_check_refs.cpp    |  7 +++----
 src/command_getid.cpp         | 13 +++++--------
 src/command_merge_changes.cpp | 13 +++++--------
 src/command_renumber.cpp      | 15 ++++-----------
 src/command_time_filter.cpp   | 11 ++++-------
 src/osmc.hpp                  | 12 ++++++++++++
 8 files changed, 42 insertions(+), 53 deletions(-)

diff --git a/src/command_apply_changes.cpp b/src/command_apply_changes.cpp
index aaa2b9a..e3b4483 100644
--- a/src/command_apply_changes.cpp
+++ b/src/command_apply_changes.cpp
@@ -36,12 +36,12 @@ bool CommandApplyChanges::setup(const std::vector<std::string>& arguments) {
 
     po::options_description cmdline("Allowed options");
     cmdline.add_options()
-    ("verbose,v", "Set verbose mode")
     ("input-format,F", po::value<std::string>(), "Format of input file")
     ("simplify,s", "Simplify change")
     ("remove-deleted,r", "Remove deleted objects from output")
     ;
 
+    add_common_options(cmdline);
     add_output_options(cmdline);
 
     po::options_description hidden("Hidden options");
@@ -60,6 +60,10 @@ bool CommandApplyChanges::setup(const std::vector<std::string>& arguments) {
     po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm);
     po::notify(vm);
 
+    setup_common(vm);
+    setup_input_file(vm);
+    setup_output_file(vm);
+
     if (vm.count("change-filenames")) {
         m_change_filenames = vm["change-filenames"].as<std::vector<std::string>>();
     }
@@ -72,13 +76,6 @@ bool CommandApplyChanges::setup(const std::vector<std::string>& arguments) {
         m_remove_deleted = true;
     }
 
-    if (vm.count("verbose")) {
-        m_vout.verbose(true);
-    }
-
-    setup_input_file(vm);
-    setup_output_file(vm);
-
     m_vout << "Started osmium apply-changes\n";
 
     m_vout << "Command line options and default settings:\n";
diff --git a/src/command_cat.cpp b/src/command_cat.cpp
index 25cf60e..ca02b17 100644
--- a/src/command_cat.cpp
+++ b/src/command_cat.cpp
@@ -35,11 +35,11 @@ bool CommandCat::setup(const std::vector<std::string>& arguments) {
 
     po::options_description cmdline("Allowed options");
     cmdline.add_options()
-    ("verbose,v", "Set verbose mode")
     ("input-format,F", po::value<std::string>(), "Format of input files")
     ("object-type,t", po::value<std::vector<std::string>>(), "Read only objects of given type (node, way, relation, changeset)")
     ;
 
+    add_common_options(cmdline);
     add_output_options(cmdline);
 
     po::options_description hidden("Hidden options");
@@ -56,9 +56,9 @@ bool CommandCat::setup(const std::vector<std::string>& arguments) {
     po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm);
     po::notify(vm);
 
-    if (vm.count("verbose")) {
-        m_vout.verbose(true);
-    }
+    setup_common(vm);
+    setup_input_files(vm);
+    setup_output_file(vm);
 
     if (vm.count("object-type")) {
         m_osm_entity_bits = osmium::osm_entity_bits::nothing;
@@ -107,9 +107,6 @@ bool CommandCat::setup(const std::vector<std::string>& arguments) {
     }
     m_vout << "\n";
 
-    setup_input_files(vm);
-    setup_output_file(vm);
-
     return true;
 }
 
diff --git a/src/command_check_refs.cpp b/src/command_check_refs.cpp
index ae5c933..42a7e02 100644
--- a/src/command_check_refs.cpp
+++ b/src/command_check_refs.cpp
@@ -39,12 +39,13 @@ bool CommandCheckRefs::setup(const std::vector<std::string>& arguments) {
 
     po::options_description cmdline("Allowed options");
     cmdline.add_options()
-    ("verbose,v", "Set verbose mode")
     ("show-ids,i", "Show IDs of missing objects")
     ("input-format,F", po::value<std::string>(), "Format of input files")
     ("check-relations,r", "Also check relations")
     ;
 
+    add_common_options(cmdline);
+
     po::options_description hidden("Hidden options");
     hidden.add_options()
     ("input-filename", po::value<std::string>(), "Input file")
@@ -59,9 +60,7 @@ bool CommandCheckRefs::setup(const std::vector<std::string>& arguments) {
     po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm);
     po::notify(vm);
 
-    if (vm.count("verbose")) {
-        m_vout.verbose(true);
-    }
+    setup_common(vm);
 
     if (vm.count("show-ids")) {
         m_show_ids = true;
diff --git a/src/command_getid.cpp b/src/command_getid.cpp
index a0bac2c..f39c3a1 100644
--- a/src/command_getid.cpp
+++ b/src/command_getid.cpp
@@ -49,10 +49,10 @@ bool CommandGetId::setup(const std::vector<std::string>& arguments) {
 
     po::options_description cmdline("Allowed options");
     cmdline.add_options()
-    ("verbose,v", "Set verbose mode")
     ("input-format,F", po::value<std::string>(), "Format of input file")
     ;
 
+    add_common_options(cmdline);
     add_output_options(cmdline);
 
     po::options_description hidden("Hidden options");
@@ -71,6 +71,10 @@ bool CommandGetId::setup(const std::vector<std::string>& arguments) {
     po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm);
     po::notify(vm);
 
+    setup_common(vm);
+    setup_input_file(vm);
+    setup_output_file(vm);
+
     if (vm.count("ids")) {
         std::string sids;
         for (const auto& s : vm["ids"].as<std::vector<std::string>>()) {
@@ -92,13 +96,6 @@ bool CommandGetId::setup(const std::vector<std::string>& arguments) {
         throw argument_error("Need at least one id to look for...");
     }
 
-    if (vm.count("verbose")) {
-        m_vout.verbose(true);
-    }
-
-    setup_input_file(vm);
-    setup_output_file(vm);
-
     m_vout << "Started osmium apply-changes\n";
 
     m_vout << "Command line options and default settings:\n";
diff --git a/src/command_merge_changes.cpp b/src/command_merge_changes.cpp
index 33870e6..588100c 100644
--- a/src/command_merge_changes.cpp
+++ b/src/command_merge_changes.cpp
@@ -37,11 +37,11 @@ bool CommandMergeChanges::setup(const std::vector<std::string>& arguments) {
 
     po::options_description cmdline("Allowed options");
     cmdline.add_options()
-    ("verbose,v", "Set verbose mode")
     ("input-format,F", po::value<std::string>(), "Format of input files")
     ("simplify,s", "Simplify change")
     ;
 
+    add_common_options(cmdline);
     add_output_options(cmdline);
 
     po::options_description hidden("Hidden options");
@@ -58,17 +58,14 @@ bool CommandMergeChanges::setup(const std::vector<std::string>& arguments) {
     po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm);
     po::notify(vm);
 
+    setup_common(vm);
+    setup_input_files(vm);
+    setup_output_file(vm);
+
     if (vm.count("simplify")) {
         m_simplify_change = true;
     }
 
-    if (vm.count("verbose")) {
-        m_vout.verbose(true);
-    }
-
-    setup_input_files(vm);
-    setup_output_file(vm);
-
     m_vout << "Started osmium merge-changes\n";
 
     m_vout << "Command line options and default settings:\n";
diff --git a/src/command_renumber.cpp b/src/command_renumber.cpp
index b893f64..bbd8e8e 100644
--- a/src/command_renumber.cpp
+++ b/src/command_renumber.cpp
@@ -45,11 +45,11 @@ bool CommandRenumber::setup(const std::vector<std::string>& arguments) {
 
     po::options_description cmdline("Allowed options");
     cmdline.add_options()
-    ("verbose,v", "Set verbose mode")
     ("input-format,F", po::value<std::string>(), "Format of input files")
     ("index-directory,i", po::value<std::string>(), "Index directory")
     ;
 
+    add_common_options(cmdline);
     add_output_options(cmdline);
 
     po::options_description hidden("Hidden options");
@@ -66,21 +66,14 @@ bool CommandRenumber::setup(const std::vector<std::string>& arguments) {
     po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm);
     po::notify(vm);
 
-    if (vm.count("verbose")) {
-        m_vout.verbose(true);
-    }
-
-    if (vm.count("output-header")) {
-        m_output_headers = vm["output-header"].as<std::vector<std::string>>();
-    }
+    setup_common(vm);
+    setup_input_file(vm);
+    setup_output_file(vm);
 
     if (vm.count("index-directory")) {
         m_index_directory = vm["index-directory"].as<std::string>();
     }
 
-    setup_input_file(vm);
-    setup_output_file(vm);
-
     m_vout << "Started osmium renumber\n";
 
     m_vout << "Command line options and default settings:\n";
diff --git a/src/command_time_filter.cpp b/src/command_time_filter.cpp
index 392ee44..fd18b28 100644
--- a/src/command_time_filter.cpp
+++ b/src/command_time_filter.cpp
@@ -35,10 +35,10 @@ bool CommandTimeFilter::setup(const std::vector<std::string>& arguments) {
 
     po::options_description cmdline("Allowed options");
     cmdline.add_options()
-    ("verbose,v", "Set verbose mode")
     ("input-format,F", po::value<std::string>(), "Format of input file")
     ;
 
+    add_common_options(cmdline);
     add_output_options(cmdline);
 
     po::options_description hidden("Hidden options");
@@ -59,9 +59,9 @@ bool CommandTimeFilter::setup(const std::vector<std::string>& arguments) {
     po::store(po::command_line_parser(arguments).options(desc).positional(positional).run(), vm);
     po::notify(vm);
 
-    if (vm.count("verbose")) {
-        m_vout.verbose(true);
-    }
+    setup_common(vm);
+    setup_input_file(vm);
+    setup_output_file(vm);
 
     m_from = osmium::Timestamp(time(0));
     m_to = m_from;
@@ -78,9 +78,6 @@ bool CommandTimeFilter::setup(const std::vector<std::string>& arguments) {
         }
     }
 
-    setup_input_file(vm);
-    setup_output_file(vm);
-
     if (m_from == m_to) { // point in time
         if (m_output_file.has_multiple_object_versions()) {
             std::cerr << "Warning! You are writing to a file marked as having multiple object versions,\n";
diff --git a/src/osmc.hpp b/src/osmc.hpp
index a841363..f2b627f 100644
--- a/src/osmc.hpp
+++ b/src/osmc.hpp
@@ -87,6 +87,18 @@ public:
     // It returns false if there was an error.
     virtual bool run() = 0;
 
+    void add_common_options(po::options_description& options) {
+        options.add_options()
+        ("verbose,v", "Set verbose mode")
+        ;
+    }
+
+    void setup_common(const boost::program_options::variables_map& vm) {
+        if (vm.count("verbose")) {
+            m_vout.verbose(true);
+        }
+    }
+
 }; // class Command
 
 class with_single_osm_input {

-- 
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