diff options
| author | Lexi Winter <lexi@le-fay.org> | 2025-07-02 00:33:19 +0100 |
|---|---|---|
| committer | Lexi Winter <lexi@le-fay.org> | 2025-07-02 00:33:19 +0100 |
| commit | 8c9688fff4446a1b0f5fe9a9be0c50084726cc4d (patch) | |
| tree | ca9a10be5795d976c0cbc73ad1111517bb4e22bf /nihil.cli/dispatch_command.cc | |
| parent | 47999457e647352ae7e71d43c65e7b39ae5ca567 (diff) | |
| download | nihil-8c9688fff4446a1b0f5fe9a9be0c50084726cc4d.tar.gz nihil-8c9688fff4446a1b0f5fe9a9be0c50084726cc4d.tar.bz2 | |
CLI cleanups; fix the FreeBSD build
Diffstat (limited to 'nihil.cli/dispatch_command.cc')
| -rw-r--r-- | nihil.cli/dispatch_command.cc | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/nihil.cli/dispatch_command.cc b/nihil.cli/dispatch_command.cc index 6e3a757..e9bf779 100644 --- a/nihil.cli/dispatch_command.cc +++ b/nihil.cli/dispatch_command.cc @@ -9,6 +9,7 @@ module nihil.cli; import nihil.std; import nihil.core; +import nihil.posix; namespace nihil { @@ -17,11 +18,11 @@ namespace { auto print_commands(command_tree_node const &node) -> void { for (auto &&child : node.children()) - std::print(std::cerr, " {}\n", child.command().path()); + std::println(std::cerr, " {}", child.command().path()); } } // namespace -auto dispatch_command(int argc, char **argv) -> int +auto dispatch_command(int const argc, char **argv) -> int { // Reset getopt(3) for the command, in case main() used it already. optreset = 1; @@ -35,12 +36,8 @@ auto dispatch_command(int argc, char **argv) -> int // Set the program name to the existing progname plus the full path to the command being // invoked; this makes error messages nicer. Save the old progname so we can restore it // after invoking the command. - auto const *old_progname = ::getprogname(); - - { - auto cprogname = std::format("{} {}", ::getprogname(), command.path()); - ::setprogname(cprogname.c_str()); - } + auto progname_guard = + setprogname(std::format("{} {}", getprogname().value_or(""), command.path())); // Invoke the command see what it returns. If it's an exit code, just return it. // Otherwise, handle the error. @@ -51,7 +48,7 @@ auto dispatch_command(int argc, char **argv) -> int auto ret = command.invoke(nrest, argv + (argc - nrest)); // Restore the old progname. - ::setprogname(old_progname); + progname_guard.release(); if (ret) return *ret; |
