20 lines
578 B
C++
20 lines
578 B
C++
|
#include "sh.h"
|
||
|
#include <errno.h>
|
||
|
#include <os/ArgumentParser.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
shell_builtin_t builtin_unset = [](int argc, char** argv) -> Result<void> {
|
||
|
StringView name;
|
||
|
|
||
|
os::ArgumentParser parser;
|
||
|
parser.set_should_exit_on_bad_usage(false);
|
||
|
parser.add_description("Remove an environment variable (shell builtin)"_sv);
|
||
|
parser.add_system_program_info("unset"_sv);
|
||
|
parser.add_positional_argument(name, "name"_sv, true);
|
||
|
if (!TRY(parser.parse(argc, argv))) return {};
|
||
|
|
||
|
if (unsetenv(name.chars()) < 0) return err(errno);
|
||
|
|
||
|
return {};
|
||
|
};
|