diff --git a/app/cli-acx/src/main/java/io/github/applecommander/acx/base/ReadWriteDiskCommandWithGlobOptions.java b/app/cli-acx/src/main/java/io/github/applecommander/acx/base/ReadWriteDiskCommandWithGlobOptions.java index 932e6c3..d297f7e 100644 --- a/app/cli-acx/src/main/java/io/github/applecommander/acx/base/ReadWriteDiskCommandWithGlobOptions.java +++ b/app/cli-acx/src/main/java/io/github/applecommander/acx/base/ReadWriteDiskCommandWithGlobOptions.java @@ -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 globs = Arrays.asList("*"); + //Subclasses must declare globs data member and implement getGlobs() method + protected abstract List getGlobs(); @Override public int handleCommand() throws Exception { List 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); } diff --git a/app/cli-acx/src/main/java/io/github/applecommander/acx/command/DeleteCommand.java b/app/cli-acx/src/main/java/io/github/applecommander/acx/command/DeleteCommand.java index 4e74a05..062c62a 100644 --- a/app/cli-acx/src/main/java/io/github/applecommander/acx/command/DeleteCommand.java +++ b/app/cli-acx/src/main/java/io/github/applecommander/acx/command/DeleteCommand.java @@ -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 globs = Arrays.asList("*"); + + @Override + protected List getGlobs(){return globs;} + @Option(names = { "-f", "--force" }, description = "Force delete locked files.") private boolean forceFlag; diff --git a/app/cli-acx/src/main/java/io/github/applecommander/acx/command/LockCommand.java b/app/cli-acx/src/main/java/io/github/applecommander/acx/command/LockCommand.java index 2c2e2d7..83f9476 100644 --- a/app/cli-acx/src/main/java/io/github/applecommander/acx/command/LockCommand.java +++ b/app/cli-acx/src/main/java/io/github/applecommander/acx/command/LockCommand.java @@ -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 globs = Arrays.asList("*"); + + @Override + protected List getGlobs(){return globs;} + public void fileHandler(FileTuple tuple) { tuple.fileEntry.setLocked(true); LOG.info(() -> String.format("File '%s' locked.", tuple.fileEntry.getFilename())); diff --git a/app/cli-acx/src/main/java/io/github/applecommander/acx/command/UnlockCommand.java b/app/cli-acx/src/main/java/io/github/applecommander/acx/command/UnlockCommand.java index c6e7a36..b5a9d6a 100644 --- a/app/cli-acx/src/main/java/io/github/applecommander/acx/command/UnlockCommand.java +++ b/app/cli-acx/src/main/java/io/github/applecommander/acx/command/UnlockCommand.java @@ -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 globs = Arrays.asList("*"); + + @Override + protected List getGlobs(){return globs;} + + public void fileHandler(FileTuple tuple) { tuple.fileEntry.setLocked(false); LOG.info(() -> String.format("File '%s' unlocked.", tuple.fileEntry.getFilename())); }