From 940b627dedc8ed30122cb9b44702452f7767b7b3 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sun, 3 Dec 2023 17:14:45 +0800 Subject: [PATCH] Add support for --version and --help options --- CMakeLists.txt | 10 ++++++++++ README.md | 14 +++++++++----- src/config.hpp.in | 17 +++++++++++++++++ src/siafu.cpp | 26 +++++++++++++++++++++++--- 4 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 src/config.hpp.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e85e298..705ab77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,6 +18,9 @@ file(GLOB_RECURSE SOURCE_FILES CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*.cpp ) +# Generate config header +configure_file(${PROJECT_SOURCE_DIR}/src/config.hpp.in ${PROJECT_BINARY_DIR}/src/config.hpp) + if(CMAKE_SYSTEM_NAME MATCHES "Windows") # Generate Windows version-information resource file @@ -40,6 +43,13 @@ set_target_properties(${PROJECT_NAME} MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>" ) +# Set executable include directories +target_include_directories(${PROJECT_NAME} + PRIVATE + ${PROJECT_SOURCE_DIR}/src + ${PROJECT_BINARY_DIR}/src +) + # Set executable compile options target_compile_options(${PROJECT_NAME} PRIVATE diff --git a/README.md b/README.md index 4305355..88fbb78 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,18 @@ cmake --build build --config Release --target install ## Usage ```bash -siafu +usage: siafu [--version] [--help] + ``` -### Parameters - - `volume_path`: Path to a sequence of uncompressed TIFF files. -- `isolevel`: Floating-point threshold value for isosurface extraction. -- `output_file`: Name and format of the output file. Supported file extensions include `.ply`, `.obj`, and `.stl`. If the file extension unrecognized, the `.ply` format will be used. +- `isolevel`: Threshold value for isosurface extraction. +- `output_file`: Output file path and format. Supported file formats include `.ply`, `.obj`, and `.stl`. If the output file extension is unrecognized, the `.ply` format will be used. + +### Options + +- `--version`: Display the version number. +- `--help`: Display usage information. ### Examples diff --git a/src/config.hpp.in b/src/config.hpp.in new file mode 100644 index 0000000..0238a77 --- /dev/null +++ b/src/config.hpp.in @@ -0,0 +1,17 @@ +// SPDX-FileCopyrightText: 2023 C. J. Howard +// SPDX-License-Identifier: MIT + +#ifndef CONFIG_HPP +#define CONFIG_HPP + +#include + +/// Siafu version string. +inline constexpr std::string_view siafu_version_string = "siafu v@PROJECT_VERSION@"; + +/// Siafu help string. +inline constexpr std::string_view siafu_help_string = + "usage: siafu [--version] [--help]\n" + " "; + +#endif // CONFIG_HPP diff --git a/src/siafu.cpp b/src/siafu.cpp index 15f6fbc..a73c3b6 100644 --- a/src/siafu.cpp +++ b/src/siafu.cpp @@ -2,26 +2,46 @@ // SPDX-License-Identifier: MIT #include "siafu.hpp" +#include "config.hpp" #include #include #include #include +#include int main(int argc, char* argv[]) { - auto usage = [](){std::cerr << "usage: \n";}; + // Parse options + if (argc > 1) + { + std::string_view option(argv[1]); + + if (option == "--version") + { + std::cout << siafu_version_string << std::endl; + return 0; + } + else if (option == "--help") + { + std::cout << siafu_help_string << std::endl; + return 0; + } + } + // Incorrect usage if (argc != 4) { - usage(); + std::cerr << siafu_help_string << std::endl; return 1; } + // Parse isolevel parameter char* endptr; f32 isolevel = std::strtof(argv[2], &endptr); if (*endptr != '\0') { - usage(); + // NaN + std::cerr << siafu_help_string << std::endl; return 1; }