-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpwd.cpp
More file actions
36 lines (31 loc) · 1011 Bytes
/
pwd.cpp
File metadata and controls
36 lines (31 loc) · 1011 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <cstdio>
#include <cfbox/args.hpp>
#include <cfbox/fs_util.hpp>
#include <cfbox/help.hpp>
#include <cfbox/error.hpp>
namespace {
constexpr cfbox::help::HelpEntry HELP = {
.name = "pwd",
.version = CFBOX_VERSION_STRING,
.one_line = "print working directory",
.usage = "pwd [-L|-P]",
.options = " -L logical path (default)\n"
" -P physical path (no symlinks)",
.extra = "",
};
} // namespace
auto pwd_main(int argc, char* argv[]) -> int {
auto parsed = cfbox::args::parse(argc, argv, {
cfbox::args::OptSpec{'L', false},
cfbox::args::OptSpec{'P', false},
});
if (parsed.has_long("help")) { cfbox::help::print_help(HELP); return 0; }
if (parsed.has_long("version")) { cfbox::help::print_version(HELP); return 0; }
auto result = cfbox::fs::current_path();
if (!result) {
CFBOX_ERR("pwd", "%s", result.error().msg.c_str());
return 1;
}
std::puts(result->c_str());
return 0;
}