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.
This commit is contained in:
Sam Atkins 2021-06-22 15:32:44 +01:00 committed by Andreas Kling
parent dd833dc220
commit e99200cc23
Notes: sideshowbarker 2024-07-18 08:34:20 +09:00

View file

@ -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;