ls: Add -1 and --directory
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
04d074538f
commit
b61307e5cb
10
apps/ls.cpp
10
apps/ls.cpp
@ -28,6 +28,8 @@ Result<int> luna_main(int argc, char** argv)
|
||||
bool human_readable { false };
|
||||
bool si { false };
|
||||
bool follow_symlink_args { false };
|
||||
bool one_per_line { false };
|
||||
bool list_directories { false };
|
||||
|
||||
os::ArgumentParser parser;
|
||||
parser.add_description("List files contained in a directory (defaults to '.', the current directory)"_sv);
|
||||
@ -41,13 +43,17 @@ Result<int> luna_main(int argc, char** argv)
|
||||
parser.add_switch_argument(si, ' ', "si"_sv, "same as -h, but show sizes in powers of 10"_sv);
|
||||
parser.add_switch_argument(follow_symlink_args, 'H', "dereference-args"_sv,
|
||||
"follow symbolic links listed as arguments"_sv);
|
||||
parser.add_switch_argument(one_per_line, '1', ""_sv, "list one file per line"_sv);
|
||||
parser.add_switch_argument(list_directories, 'd', "directory"_sv, "list directories instead of their contents"_sv);
|
||||
parser.parse(argc, argv);
|
||||
|
||||
Vector<String> files;
|
||||
int dirfd = AT_FDCWD;
|
||||
SharedPtr<os::Directory> dir;
|
||||
|
||||
if (os::FileSystem::is_directory(pathname, follow_symlink_args))
|
||||
if (!long_list) follow_symlink_args = true;
|
||||
|
||||
if (os::FileSystem::is_directory(pathname, follow_symlink_args) && !list_directories)
|
||||
{
|
||||
dir = TRY(os::Directory::open(pathname));
|
||||
dirfd = dir->fd();
|
||||
@ -69,7 +75,7 @@ Result<int> luna_main(int argc, char** argv)
|
||||
|
||||
if (!long_list)
|
||||
{
|
||||
auto list = TRY(String::join(files, " "_sv));
|
||||
auto list = TRY(String::join(files, one_per_line ? "\n"_sv : " "_sv));
|
||||
if (!list.is_empty()) os::println("%s", list.chars());
|
||||
}
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user