From 33675c18ec88a95c0fb2e81f9ed59c7d15d07d96 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Tue, 24 Oct 2023 12:12:17 -0700 Subject: [PATCH] Flags: show default value. --- CMakeLists.txt | 2 +- include/scmp/geom/Quaternion.h | 2 +- src/sl/Flags.cc | 38 ++++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7bd31fa..7d34897 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.22) project(scsl LANGUAGES CXX - VERSION 1.1.1 + VERSION 1.1.2 DESCRIPTION "Shimmering Clarity Standard Library") set(CMAKE_CXX_STANDARD 14) diff --git a/include/scmp/geom/Quaternion.h b/include/scmp/geom/Quaternion.h index 40557d7..fdadb24 100644 --- a/include/scmp/geom/Quaternion.h +++ b/include/scmp/geom/Quaternion.h @@ -42,7 +42,7 @@ namespace geom { /// and rotations in three dimensions. /// /// Quaternions encode rotations in three-dimensional space. While -/// technically a MakeQuaternion is comprised of a real element and a +/// technically a Quaternion is comprised of a real element and a /// complex vector<3>, for the purposes of this library, it is modeled /// as a floating point 4D vector of the form , where x, y, /// and z represent an Axis of rotation in R3 and w the Angle, in diff --git a/src/sl/Flags.cc b/src/sl/Flags.cc index 1e9bec6..316b261 100644 --- a/src/sl/Flags.cc +++ b/src/sl/Flags.cc @@ -25,16 +25,16 @@ #include #include -#include #include #include +#include namespace scsl { static const std::regex isFlag("^--?[a-zA-Z0-9][a-zA-Z0-9-_]*$", - std::regex_constants::nosubs|std::regex_constants::optimize); + std::regex_constants::nosubs | std::regex_constants::optimize); std::string Flags::ParseStatusToString(ParseStatus status) @@ -82,7 +82,7 @@ Flags::Flags(std::string fName, std::string fDescription) Flags::~Flags() { - for (auto &flag : this->flags) { + for (auto &flag: this->flags) { if (flag.second->Type == FlagType::String) { delete flag.second->Value.s; } @@ -300,7 +300,6 @@ Flags::Parse(int argc, char **argv, bool skipFirst) throw std::runtime_error("unhandled parse state"); #endif } - } return ParseStatus::OK; @@ -313,26 +312,44 @@ Flags::Usage(std::ostream &os, int exitCode) os << this->name << ":\t"; auto indent = this->name.size() + 7; - scstring::WriteTabIndented(os, description, 72 - indent, indent / 8, false); + scstring::WriteTabIndented(os, this->description, 72 - indent, + indent / 8, false); os << "\n\n"; - for (const auto &pair : this->flags) { + for (const auto &pair: this->flags) { + auto argDesc = pair.second->Description; + if (!argDesc.empty()) { + argDesc += ' '; + } auto argLine = "\t" + pair.first; switch (pair.second->Type) { case FlagType::Boolean: argLine += "\t\t"; + argDesc += "(default=false)"; break; case FlagType::Integer: argLine += " int\t\t"; + if (pair.second->Value.i != 0) { + argDesc += "(default=" + std::to_string(pair.second->Value.i) + ")"; + } break; case FlagType::UnsignedInteger: argLine += " uint\t\t"; + if (pair.second->Value.u != 0) { + argDesc += "(default=" + std::to_string(pair.second->Value.u) + ")"; + } break; case FlagType::SizeT: argLine += " size_t\t"; + if (pair.second->Value.size != 0) { + argDesc += "(default=" + std::to_string(pair.second->Value.size) + ")"; + } break; case FlagType::String: argLine += " string\t"; + if (pair.second->Value.s != nullptr && !(pair.second->Value.s->empty())) { + argDesc += "(default=" + *(pair.second->Value.s) + ")"; + } break; case FlagType::Unknown: // fallthrough @@ -347,8 +364,8 @@ Flags::Usage(std::ostream &os, int exitCode) os << argLine; indent = argLine.size(); - scstring::WriteTabIndented(os, pair.second->Description, - 72-indent, (indent/8)+2, false); + scstring::WriteTabIndented(os, argDesc, 72 - indent, + (indent / 8) + 2, false); } os << "\n"; @@ -382,7 +399,7 @@ Flags::Arg(size_t i) Flag * -Flags::checkGetArg(std::string& fName, FlagType eType) +Flags::checkGetArg(std::string &fName, FlagType eType) { if (this->flags[fName] == nullptr) { return nullptr; @@ -455,5 +472,4 @@ Flags::GetString(std::string fName, std::string &flagValue) } -} // namespace scsl - +}// namespace scsl