}
@Override
public Result execute(ShellContext context) throws Exception
{
Shell shell = context.getProvider();
FileResource<?> currentResource = shell.getCurrentResource();
for (String file : arguments.getValue())
{
List<Resource<?>> resources = new PathspecParser(resourceFactory, currentResource, file).resolve();
for (Resource<?> resource : resources)
{
if (!resource.exists())
{
return Results.fail(file + ": No such file or directory");
}
}
}
boolean forceOption = force.getValue();
boolean recurse = recursive.getValue();
for (String file : arguments.getValue())
{
List<Resource<?>> resources = new PathspecParser(resourceFactory, currentResource, file).resolve();
for (Resource<?> resource : resources)
{
// TODO: Prompt for removal
if (forceOption)
{
if (!resource.delete(recurse))
{
return Results.fail("rm: cannot remove ‘" + resource.getFullyQualifiedName()
+ "’: No such file or directory");
}
}
}
}
while (!currentResource.exists())
{
currentResource = currentResource.getParent();
}
shell.setCurrentResource(currentResource);
return Results.success();
}