diff options
author | Sam Atkins <atkinssj@gmail.com> | 2021-06-22 15:32:44 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-22 12:48:44 +0200 |
commit | e99200cc23c8ddf45ac93fd6236a5dd137921b1c (patch) | |
tree | 552d6653eff233ac91498e98dde234a23af21c4b | |
parent | dd833dc220c1980c45aa708df4a76a47bb7ce3cf (diff) | |
download | serenity-e99200cc23c8ddf45ac93fd6236a5dd137921b1c.zip |
FileOperation: Combine 'sources' and 'destination' CL arguments
The upcoming 'Delete' operation has no destination, so this was the
best solution we could come up with for now. Perhaps ArgsParser
could support sub-commands, so we would define 'Copy', 'Move' and
'Delete' each as sub-commands with their own argument definitions.
That would make things like git's variety of commands possible.
-rw-r--r-- | Userland/Services/FileOperation/main.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Userland/Services/FileOperation/main.cpp b/Userland/Services/FileOperation/main.cpp index 1156db5ca5..22b7a36b8c 100644 --- a/Userland/Services/FileOperation/main.cpp +++ b/Userland/Services/FileOperation/main.cpp @@ -36,19 +36,23 @@ static void report_warning(String message); int main(int argc, char** argv) { String operation; - Vector<String> sources; - String destination; + Vector<String> paths; Core::ArgsParser args_parser; args_parser.add_positional_argument(operation, "Operation: either 'Copy' or 'Move'", "operation", Core::ArgsParser::Required::Yes); - args_parser.add_positional_argument(sources, "Sources", "sources", Core::ArgsParser::Required::Yes); - args_parser.add_positional_argument(destination, "Destination", "destination", Core::ArgsParser::Required::Yes); + args_parser.add_positional_argument(paths, "Source paths, followed by a destination if applicable", "paths", Core::ArgsParser::Required::Yes); args_parser.parse(argc, argv); + String destination = paths.take_last(); + if (paths.is_empty()) { + report_warning("At least one source and destination are required"); + return 1; + } + if (operation == "Copy") - return perform_copy(sources, destination); + return perform_copy(paths, destination); if (operation == "Move") - return perform_move(sources, destination); + return perform_move(paths, destination); report_warning(String::formatted("Unknown operation '{}'", operation)); return 0; |