Skip to content

Commit 8f64b71

Browse files
cleanup command line options
1 parent 238e061 commit 8f64b71

File tree

5 files changed

+66
-36
lines changed

5 files changed

+66
-36
lines changed

scripts/gen_version_info_cpp.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [ $# -ne 1 ]; then
77
>&2 echo "usage: $0 project_name"
88
fi
99

10-
project_name=$(echo "$1" | sed -e "s/\\s/_/" -e "s/-/_/")
10+
project_name=$(echo "$1" | sed -e "s/\\s/_/g" -e "s/-/_/g")
1111

1212
# "$(git rev-parse HEAD)$(test $(git status --porcelain | wc -l) -gt 0 && printf -- -dirty)"
1313
GIT_HASH=$(git rev-parse HEAD)

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ target_sources(${Target} PRIVATE readline.hpp)
2020

2121
# ---------------------------------------- subdirectories --------------------------------------------------------------
2222
# ======================================================================================================================
23+
add_subdirectory(generated)

src/generated/version_info.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
#include "version_info.hpp"
99

10-
const std::string stdin_to-modbus-shm_version_info::VERSION_STR(PROJECT_VERSION);
11-
const std::string stdin_to-modbus-shm_version_info::NAME(PROJECT_NAME);
12-
const std::string stdin_to-modbus-shm_version_info::COMPILER(COMPILER_INFO);
13-
const std::string stdin_to-modbus-shm_version_info::SYSTEM(SYSTEM_INFO);
14-
const std::string stdin_to-modbus-shm_version_info::GIT_HASH("cea9d0580e2b76930a8c2c8bcfe6ed376f640233-dirty");
10+
const std::string stdin_to_modbus_shm_version_info::VERSION_STR(PROJECT_VERSION);
11+
const std::string stdin_to_modbus_shm_version_info::NAME(PROJECT_NAME);
12+
const std::string stdin_to_modbus_shm_version_info::COMPILER(COMPILER_INFO);
13+
const std::string stdin_to_modbus_shm_version_info::SYSTEM(SYSTEM_INFO);
14+
const std::string stdin_to_modbus_shm_version_info::GIT_HASH("60e5df975348194055772e16e37c5b2a6d98e18d-dirty");

src/generated/version_info.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @brief struct that contains version information
1212
* @details contains only static members --> no instance can be created
1313
*/
14-
struct stdin_to-modbus-shm_version_info {
14+
struct stdin_to_modbus_shm_version_info {
1515
//* Mayor version number
1616
static constexpr int MAYOR = PROJECT_VERSION_MAJOR;
1717

@@ -43,5 +43,5 @@ struct stdin_to-modbus-shm_version_info {
4343
static const std::string GIT_HASH;
4444

4545
private:
46-
stdin_to-modbus-shm_version_info() = default;
46+
stdin_to_modbus_shm_version_info() = default;
4747
};

src/main.cpp

Lines changed: 57 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "cxxsemaphore.hpp"
1111
#include "cxxshm.hpp"
12+
#include "generated/version_info.hpp"
1213
#include <array>
1314
#include <chrono>
1415
#include <cmath>
@@ -82,32 +83,38 @@ int main(int argc, char **argv) {
8283
}
8384

8485
// all command line arguments
85-
options.add_options()("n,name-prefix",
86-
"name prefix of the shared memory objects",
87-
cxxopts::value<std::string>()->default_value("modbus_"));
88-
options.add_options()("address-base",
89-
"Numerical base (radix) that is used for the addresses (see "
90-
"https://en.cppreference.com/w/cpp/string/basic_string/stoul)",
91-
cxxopts::value<int>()->default_value("0"));
92-
options.add_options()("value-base",
93-
"Numerical base (radix) that is used for the values (see "
94-
"https://en.cppreference.com/w/cpp/string/basic_string/stoul)",
95-
cxxopts::value<int>()->default_value("0"));
96-
options.add_options()("p,passthrough", "write passthrough all executed commands to stdout");
97-
options.add_options()("bash", "passthrough as bash script. No effect i '--passthrough' is not set");
98-
options.add_options()("valid-hist", "add only valid commands to command history");
99-
options.add_options()("h,help", "print usage");
100-
options.add_options()("v,verbose", "print what is written to the registers");
101-
options.add_options()("version", "print version information");
102-
options.add_options()("license", "show licenses");
103-
options.add_options()("data-types", "show list of supported data type identifiers");
104-
options.add_options()("constants", "list string constants that can be used as value");
105-
options.add_options()("semaphore",
106-
"protect the shared memory with an existing named semaphore against simultaneous access",
107-
cxxopts::value<std::string>());
108-
options.add_options()("semaphore-timeout",
109-
"maximum time (in seconds) to wait for semaphore (default: 0.1)",
110-
cxxopts::value<double>()->default_value("0.1"));
86+
options.add_options("shared memory")("n,name-prefix",
87+
"name prefix of the shared memory objects",
88+
cxxopts::value<std::string>()->default_value("modbus_"));
89+
options.add_options("settings")("address-base",
90+
"Numerical base (radix) that is used for the addresses (see "
91+
"https://en.cppreference.com/w/cpp/string/basic_string/stoul)",
92+
cxxopts::value<int>()->default_value("0"));
93+
options.add_options("settings")("value-base",
94+
"Numerical base (radix) that is used for the values (see "
95+
"https://en.cppreference.com/w/cpp/string/basic_string/stoul)",
96+
cxxopts::value<int>()->default_value("0"));
97+
options.add_options("settings")("p,passthrough", "write passthrough all executed commands to stdout");
98+
options.add_options("settings")("bash", "passthrough as bash script. No effect i '--passthrough' is not set");
99+
options.add_options("settings")("valid-hist", "add only valid commands to command history");
100+
options.add_options("other")("h,help", "print usage");
101+
options.add_options("other")("v,verbose", "print what is written to the registers");
102+
options.add_options("version information")("version", "print version and exit");
103+
options.add_options("version information")("longversion",
104+
"print version (including compiler and system info) and exit");
105+
options.add_options("version information")("shortversion", "print version (only version string) and exit");
106+
options.add_options("version information")("git-hash", "print git hash");
107+
options.add_options("other")("license", "show licenses");
108+
options.add_options("other")("license-full", "show licences (full license text)");
109+
options.add_options("other")("data-types", "show list of supported data type identifiers");
110+
options.add_options("other")("constants", "list string constants that can be used as value");
111+
options.add_options("shared memory")(
112+
"semaphore",
113+
"protect the shared memory with an existing named semaphore against simultaneous access",
114+
cxxopts::value<std::string>());
115+
options.add_options("shared memory")("semaphore-timeout",
116+
"maximum time (in seconds) to wait for semaphore (default: 0.1)",
117+
cxxopts::value<double>()->default_value("0.1"));
111118

112119
// parse arguments
113120
cxxopts::ParseResult args;
@@ -168,9 +175,26 @@ int main(int argc, char **argv) {
168175
}
169176

170177
// print version
178+
if (args.count("shortversion")) {
179+
std::cout << PROJECT_VERSION << '\n';
180+
return EX_OK;
181+
}
182+
171183
if (args.count("version")) {
172-
std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << " (compiled with " << COMPILER_INFO << " on "
173-
<< SYSTEM_INFO << ')' << '\n';
184+
std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << '\n';
185+
return EX_OK;
186+
}
187+
188+
if (args.count("longversion")) {
189+
std::cout << PROJECT_NAME << ' ' << PROJECT_VERSION << '\n';
190+
std::cout << " compiled with " << COMPILER_INFO << '\n';
191+
std::cout << " on system " << SYSTEM_INFO << '\n';
192+
std::cout << " from git commit " << RCS_HASH << '\n';
193+
return EX_OK;
194+
}
195+
196+
if (args.count("git-hash")) {
197+
std::cout << RCS_HASH << '\n';
174198
return EX_OK;
175199
}
176200

@@ -180,6 +204,11 @@ int main(int argc, char **argv) {
180204
return EX_OK;
181205
}
182206

207+
if (args.count("license-full")) {
208+
print_licenses(std::cout, true);
209+
return EX_OK;
210+
}
211+
183212
auto print_data_types = []() {
184213
std::cout << "Supported data types:" << '\n';
185214
std::cout << " - Float:" << '\n';

0 commit comments

Comments
 (0)