Skip to content

Commit 66c8f04

Browse files
committed
Better logs around sync
1 parent 23d8f7f commit 66c8f04

4 files changed

Lines changed: 28 additions & 14 deletions

File tree

src/main/java/net/sony/dpt/fuse/DptFuseMounter.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,13 @@ public void mountDpt(Path mountPoint) throws IOException, InterruptedException {
316316
documentEntriesMap.put(path, entry);
317317
}
318318
try {
319+
logWriter.log("Mounted the Digital Paper on " + mountPoint + ", type Ctrl+C to unmount");
320+
321+
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
322+
umount();
323+
logWriter.log("Digital Paper unmounted from " + mountPoint);
324+
}));
325+
319326
mount(mountPoint, true, false);
320327
}
321328
finally {

src/main/java/net/sony/dpt/persistence/LastCommandRunStore.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
import java.io.IOException;
88
import java.nio.file.Files;
99
import java.nio.file.Path;
10-
import java.util.Arrays;
11-
import java.util.HashMap;
12-
import java.util.List;
13-
import java.util.Map;
10+
import java.util.*;
1411

1512
/**
1613
* This stores the last command parameters, which allows then to autofill the params for a next run
@@ -67,4 +64,21 @@ public List<String> retrieve(Command command) {
6764
Map<String, List<String>> persisted = retrieve();
6865
return persisted.getOrDefault(command.toString(), null);
6966
}
67+
68+
/**
69+
* Utility function doing all the work to retrive just one argument for simple commands
70+
* @param command The command we'll retrieve args for
71+
* @param arguments The args list passed to the CLI
72+
* @return The one argument, either from this store, or from the command-line.
73+
*/
74+
public String retrieveOneArgument(Command command, List<String> arguments) {
75+
String singleArgument;
76+
if (arguments.size() - 1 < command.getArgumentNames().size()) {
77+
singleArgument = retrieve(command).get(0);
78+
} else {
79+
singleArgument = arguments.get(1);
80+
store(command, singleArgument);
81+
}
82+
return singleArgument;
83+
}
7084
}

src/main/java/net/sony/dpt/ui/cli/Command.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public enum Command {
3535
CHECK_FIRMWARE("check-firmware", "Check if a new firmware version has been published"),
3636
UPDATE_FIRMWARE("update-firmware", Arrays.asList(CommandOption.FORCE, CommandOption.DRYRUN), Collections.emptyList(), "Check for update and update the firmware if needed. Will ask for confirmation before triggering the update. Use -dryrun to test the process."),
3737
RAW_GET("get", Collections.emptyList(), Collections.singletonList("url"), "Sends and display a GET request to the Digital Paper"),
38-
MOUNT("mount", Collections.emptyList(), Collections.singletonList("mount-point"), "FUSE-mount the DPT at the specified mount point."),
38+
MOUNT("mount", Collections.emptyList(), Collections.singletonList("[mount-point]"), "FUSE-mount the DPT at the specified mount point. If not mount point is specified, it will attempt to use the one passed previously"),
3939
HELP(Arrays.asList("help", "command-help"), "Prints this message");
4040

4141
private final List<String> commandNames;

src/main/java/net/sony/dpt/ui/cli/DigitalPaperCLI.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,7 @@ public void execute(String[] args) throws Exception {
222222
new Whiteboard(new TakeScreenshotCommand(digitalPaperEndpoint));
223223
break;
224224
case SYNC:
225-
String localSyncFolder;
226-
if (arguments.size() - 1 < command.getArgumentNames().size()) {
227-
localSyncFolder = lastCommandRunStore.retrieve(command).get(0);
228-
} else {
229-
localSyncFolder = arguments.get(1);
230-
lastCommandRunStore.store(command, localSyncFolder);
231-
}
232-
sync(localSyncFolder, dryrun);
225+
sync(lastCommandRunStore.retrieveOneArgument(command, arguments), dryrun);
233226
break;
234227
case DIALOG:
235228
showDialog(arguments.get(1), arguments.get(2), arguments.get(3));
@@ -283,7 +276,7 @@ public void execute(String[] args) throws Exception {
283276
whiteboardHtml();
284277
break;
285278
case MOUNT:
286-
mount(arguments.get(1));
279+
mount(lastCommandRunStore.retrieveOneArgument(command, arguments));
287280
break;
288281
}
289282

0 commit comments

Comments
 (0)