diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-07-01 19:18:42 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-07-01 19:18:42 +0100 |
| commit | 378dd663a402fe196f2b56c6413eb3f623aecbbf (patch) | |
| tree | 6d13f14ff8f9bff7c55a30eb046af489d0f677a2 /nihil.cli/command.cc | |
| parent | 2e2d1bd3b6c7776b77c33b94f30ead89367a71e6 (diff) | |
| download | nihil-378dd663a402fe196f2b56c6413eb3f623aecbbf.tar.gz nihil-378dd663a402fe196f2b56c6413eb3f623aecbbf.tar.bz2 | |
cli: refactoring
Diffstat (limited to 'nihil.cli/command.cc')
| -rw-r--r-- | nihil.cli/command.cc | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/nihil.cli/command.cc b/nihil.cli/command.cc deleted file mode 100644 index 6271cc6..0000000 --- a/nihil.cli/command.cc +++ /dev/null @@ -1,44 +0,0 @@ -// This source code is released into the public domain. -module; - -// For EX_USAGE. While <sysexits.h> is deprecated, there's no other standard -// exit code for 'usage error'; some programs use 2 (common on Linux), but -// 2 is also used for many other exit codes. -#include <sysexits.h> - -module nihil.cli; - -import nihil.std; -import nihil.error; -import :registry; - -namespace nihil { - -//NOLINTNEXTLINE(bugprone-easily-swappable-parameters) -command::command(std::string_view path, std::string_view usage, - command_function_t handler) - : command_node(path) - , m_usage(usage) - , m_handler(std::move(handler)) -{ - register_command(this); -} - -auto command::usage(this command const &self) noexcept -> std::string_view -{ - return self.m_usage; -} - -auto command::invoke(int argc, char **argv) const - -> std::expected<int, error> -{ - try { - return std::invoke(m_handler, argc, argv); - } catch (usage_error const &err) { - std::print(std::cerr, "{}\n", err.what()); - std::print(std::cerr, "usage: {} {}", path(), usage()); - return EX_USAGE; - } -} - -} // namespace nihil |
