Skip to content

Commit

Permalink
Add support for --version and --help options
Browse files Browse the repository at this point in the history
  • Loading branch information
cjhoward committed Dec 3, 2023
1 parent fe6b65d commit 940b627
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,6 +43,13 @@ set_target_properties(${PROJECT_NAME}
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>: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
Expand Down
14 changes: 9 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,18 @@ cmake --build build --config Release --target install
## Usage

```bash
siafu <volume_path> <isolevel> <output_file>
usage: siafu [--version] [--help]
<volume_path> <isolevel> <output_file>
```

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

Expand Down
17 changes: 17 additions & 0 deletions src/config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2023 C. J. Howard
// SPDX-License-Identifier: MIT

#ifndef CONFIG_HPP
#define CONFIG_HPP

#include <string_view>

/// 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"
" <volume_path> <isolevel> <output_file>";

#endif // CONFIG_HPP
26 changes: 23 additions & 3 deletions src/siafu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,46 @@
// SPDX-License-Identifier: MIT

#include "siafu.hpp"
#include "config.hpp"
#include <fstream>
#include <iostream>
#include <format>
#include <stdexcept>
#include <string_view>

int main(int argc, char* argv[])
{
auto usage = [](){std::cerr << "usage: <volume_path> <isolevel> <output_file>\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;
}

Expand Down

0 comments on commit 940b627

Please sign in to comment.