Luna/shell/builtin/exit.cpp

21 lines
621 B
C++
Raw Permalink Normal View History

2023-07-21 19:06:10 +00:00
#include "sh.h"
#include <os/ArgumentParser.h>
#include <stdlib.h>
shell_builtin_t builtin_exit = [](int argc, char** argv) -> Result<void> {
StringView exit_status;
os::ArgumentParser parser;
parser.set_should_exit_on_bad_usage(false);
parser.add_description("Exit the shell (shell builtin)"_sv);
parser.add_system_program_info("exit"_sv);
parser.add_positional_argument(exit_status, "status"_sv, false);
if (!TRY(parser.parse(argc, argv))) return {};
int status = 0;
if (!exit_status.is_empty()) { status = (int)strtoul(exit_status.chars(), nullptr, 10); }
exit(status);
};