mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:48:11 +00:00
rmdir: Add -v
option to list each directory as it is removed
This commit is contained in:
parent
307dc00ee0
commit
cba46a2d64
2 changed files with 6 additions and 0 deletions
|
@ -15,6 +15,7 @@ Remove given `directory(ies)`, if they are empty
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
* `-p`, `--parents`: Remove all directories in each given path
|
* `-p`, `--parents`: Remove all directories in each given path
|
||||||
|
* `-v`, `--verbose`: List each directory as it is removed
|
||||||
|
|
||||||
## Arguments
|
## Arguments
|
||||||
|
|
||||||
|
|
|
@ -16,16 +16,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
TRY(Core::System::pledge("stdio cpath"));
|
TRY(Core::System::pledge("stdio cpath"));
|
||||||
|
|
||||||
bool remove_parents = false;
|
bool remove_parents = false;
|
||||||
|
bool verbose = false;
|
||||||
Vector<StringView> paths;
|
Vector<StringView> paths;
|
||||||
|
|
||||||
Core::ArgsParser args_parser;
|
Core::ArgsParser args_parser;
|
||||||
args_parser.add_option(remove_parents, "Remove all directories in each given path", "parents", 'p');
|
args_parser.add_option(remove_parents, "Remove all directories in each given path", "parents", 'p');
|
||||||
|
args_parser.add_option(verbose, "List each directory as it is removed", "verbose", 'v');
|
||||||
args_parser.add_positional_argument(paths, "Directories to remove", "paths");
|
args_parser.add_positional_argument(paths, "Directories to remove", "paths");
|
||||||
args_parser.parse(arguments);
|
args_parser.parse(arguments);
|
||||||
|
|
||||||
int status = 0;
|
int status = 0;
|
||||||
|
|
||||||
auto remove_directory = [&](StringView path) {
|
auto remove_directory = [&](StringView path) {
|
||||||
|
if (verbose)
|
||||||
|
outln("rmdir: removing directory '{}'", path);
|
||||||
|
|
||||||
auto maybe_error = Core::System::rmdir(path);
|
auto maybe_error = Core::System::rmdir(path);
|
||||||
if (maybe_error.is_error()) {
|
if (maybe_error.is_error()) {
|
||||||
warnln("Failed to remove '{}': {}", path, maybe_error.release_error());
|
warnln("Failed to remove '{}': {}", path, maybe_error.release_error());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue