Merge pull request #93 from ThomasFok/fix/lock_del_cmd_help_msg

acx - help messages of delete and lock command are wrong
This commit is contained in:
A2 Geek 2023-02-11 18:14:51 -06:00 committed by GitHub
commit 801cf68745
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 33 additions and 8 deletions

View File

@ -28,25 +28,23 @@ import com.webcodepro.applecommander.util.filestreamer.FileStreamer;
import com.webcodepro.applecommander.util.filestreamer.FileTuple;
import com.webcodepro.applecommander.util.filestreamer.TypeOfFile;
import picocli.CommandLine.Parameters;
public abstract class ReadWriteDiskCommandWithGlobOptions extends ReadWriteDiskCommandOptions {
private static Logger LOG = Logger.getLogger(ReadWriteDiskCommandWithGlobOptions.class.getName());
@Parameters(arity = "1..*", description = "File glob(s) to unlock (default = '*') - be cautious of quoting!")
private List<String> globs = Arrays.asList("*");
//Subclasses must declare globs data member and implement getGlobs() method
protected abstract List<String> getGlobs();
@Override
public int handleCommand() throws Exception {
List<FileTuple> files = FileStreamer.forDisk(disk)
.ignoreErrors(true)
.includeTypeOfFile(TypeOfFile.FILE)
.matchGlobs(globs)
.matchGlobs(this.getGlobs())
.stream()
.collect(Collectors.toList());
if (files.isEmpty()) {
LOG.warning(() -> String.format("No matches found for %s.", String.join(",", globs)));
LOG.warning(() -> String.format("No matches found for %s.", String.join(",", this.getGlobs())));
} else {
files.forEach(this::fileHandler);
}

View File

@ -20,18 +20,27 @@
package io.github.applecommander.acx.command;
import java.util.logging.Logger;
import java.util.Arrays;
import java.util.List;
import com.webcodepro.applecommander.util.filestreamer.FileTuple;
import io.github.applecommander.acx.base.ReadWriteDiskCommandWithGlobOptions;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
@Command(name = "delete", description = "Delete file(s) from a disk image.",
aliases = { "del", "rm" })
public class DeleteCommand extends ReadWriteDiskCommandWithGlobOptions {
private static Logger LOG = Logger.getLogger(DeleteCommand.class.getName());
@Parameters(arity = "1..*", description = "File glob(s) to delete (default = '*') - be cautious of quoting!")
private List<String> globs = Arrays.asList("*");
@Override
protected List<String> getGlobs(){return globs;}
@Option(names = { "-f", "--force" }, description = "Force delete locked files.")
private boolean forceFlag;

View File

@ -20,16 +20,25 @@
package io.github.applecommander.acx.command;
import java.util.logging.Logger;
import java.util.Arrays;
import java.util.List;
import com.webcodepro.applecommander.util.filestreamer.FileTuple;
import io.github.applecommander.acx.base.ReadWriteDiskCommandWithGlobOptions;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
@Command(name = "lock", description = "Lock file(s) on a disk image.")
public class LockCommand extends ReadWriteDiskCommandWithGlobOptions {
private static Logger LOG = Logger.getLogger(LockCommand.class.getName());
@Parameters(arity = "1..*", description = "File glob(s) to lock (default = '*') - be cautious of quoting!")
private List<String> globs = Arrays.asList("*");
@Override
protected List<String> getGlobs(){return globs;}
public void fileHandler(FileTuple tuple) {
tuple.fileEntry.setLocked(true);
LOG.info(() -> String.format("File '%s' locked.", tuple.fileEntry.getFilename()));

View File

@ -20,17 +20,26 @@
package io.github.applecommander.acx.command;
import java.util.logging.Logger;
import java.util.Arrays;
import java.util.List;
import com.webcodepro.applecommander.util.filestreamer.FileTuple;
import io.github.applecommander.acx.base.ReadWriteDiskCommandWithGlobOptions;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
@Command(name = "unlock", description = "Unlock file(s) on a disk image.")
public class UnlockCommand extends ReadWriteDiskCommandWithGlobOptions {
private static Logger LOG = Logger.getLogger(UnlockCommand.class.getName());
public void fileHandler(FileTuple tuple) {
@Parameters(arity = "1..*", description = "File glob(s) to unlock (default = '*') - be cautious of quoting!")
private List<String> globs = Arrays.asList("*");
@Override
protected List<String> getGlobs(){return globs;}
public void fileHandler(FileTuple tuple) {
tuple.fileEntry.setLocked(false);
LOG.info(() -> String.format("File '%s' unlocked.", tuple.fileEntry.getFilename()));
}