Restructure into umbrella modules (~55 -> 16 targets)
Headers move, CMake targets merge, C++ namespaces stay unchanged: - Core: Scope, Lazy, Counted, Flags, Hash, Bits, Uuid, TypeList, TypeMap, Variant - Functional: Pipeline, Either, Result, Retry - Containers: Ring, Pool, PriorityQueue, LRU, Trie, Graph, DisjointSet, Bitset, Interval - Math: +Matrix, Numeric, Random, Histogram - Text: Str, Format, Tokenizer, Diff, Encoding, Semver - Data: Json, Csv, Ini - Async: Coro, Concurrency, EventBus, Observable - Time: +Bench - Log: Log facade + Logging framework (facade now header-only, breaking the Stacktrace<->Log link cycle the merge would have created) - System: FileSystem + Process - Configuration: +Argparse - Unchanged: Stacktrace, Plugin, StateMachine, Testing, TestingMock, Detail Module system fixes: - OPTIONAL_DEPS resolution deferred to void_finalize_modules() so it no longer depends on the alphabetical discovery order of src/ subdirs (Testing -> Text would have been silently dropped). - Every header-only module now has a tracked module.cmake; previously the empty src/<Name> marker dirs were untracked, so a fresh clone would have silently skipped those modules. - VOID_HAS_LOGGING/CONCURRENCY/STR consumers renamed to LOG/ASYNC/TEXT. Tests move to tests/standalone/<Umbrella>/<Feature>.cpp (Result suite files prefixed: ResultBasic etc.). Test count verified identical (831) before and after. README/CLAUDE.md module tables updated. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
da2e93c405
commit
28b94883fd
156 files changed
+278
-220
No files matched your search
@@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <expected>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace Void::Argparse
|
||||
{
|
||||
|
||||
// ── Parser ────────────────────────────────────────────────────────────────────
|
||||
// Fluent command-line argument parser.
|
||||
//
|
||||
// Supports:
|
||||
// --flag, -f boolean flag (default false, set to true by presence)
|
||||
// --key=value option with value (= or space separator)
|
||||
// --key value option with value
|
||||
// positional args collected in declaration order
|
||||
// --help / -h auto-generated help text
|
||||
|
||||
class Parser
|
||||
{
|
||||
public:
|
||||
explicit Parser(std::string program, std::string description = {});
|
||||
|
||||
// Add a boolean flag.
|
||||
// long_name: e.g. "--verbose" short_name: e.g. "-v" (short_name may be "")
|
||||
Parser& flag(std::string_view long_name, std::string_view short_name,
|
||||
std::string_view description, bool& out);
|
||||
|
||||
// Add an option that takes a value. If not provided, out stays nullopt.
|
||||
Parser& option(std::string_view long_name, std::string_view short_name,
|
||||
std::string_view description, std::optional<std::string>& out);
|
||||
|
||||
// Add an option with a default value. out is always set after parse().
|
||||
Parser& option_default(std::string_view long_name, std::string_view short_name,
|
||||
std::string_view description, std::string& out,
|
||||
std::string_view default_value = "");
|
||||
|
||||
// Add a required positional argument.
|
||||
Parser& positional(std::string_view name, std::string_view description, std::string& out);
|
||||
|
||||
// Parse argc/argv. Returns error message on failure.
|
||||
[[nodiscard]] std::expected<void, std::string>
|
||||
parse(int argc, const char* const* argv) const;
|
||||
|
||||
// Returns formatted help text.
|
||||
[[nodiscard]] std::string help() const;
|
||||
|
||||
private:
|
||||
struct FlagEntry { std::string lng, sht, desc; bool* out; };
|
||||
struct OptionEntry{ std::string lng, sht, desc, def; std::optional<std::string>* out_opt; std::string* out_str; };
|
||||
struct PosEntry { std::string name, desc; std::string* out; };
|
||||
|
||||
std::string program_, description_;
|
||||
std::vector<FlagEntry> flags_;
|
||||
std::vector<OptionEntry> options_;
|
||||
std::vector<PosEntry> positionals_;
|
||||
};
|
||||
|
||||
} // namespace Void::Argparse
|
||||
Reference in new issue
Block a user