com.sshtools.commands.Updates Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of command-utils Show documentation
Show all versions of command-utils Show documentation
Utility classes for creating SSH enabled commands with Maverick Synergy
The newest version!
package com.sshtools.commands;
import java.util.Optional;
import java.util.concurrent.Callable;
import com.sshtools.jaul.Phase;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Parameters;
import picocli.CommandLine.Spec;
public class Updates {
public static Integer call(JadaptiveCommand root) throws Exception {
var updateService = root.getUpdateService();
var terminal = root.getTerminal();
updateService.checkForUpdate();
if (updateService.isNeedsUpdating()) {
terminal.messageln("Updating. [{0} -> {1}]", root.getVersion(), updateService.getAvailableVersion());
updateService.update();
} else
terminal.messageln("No update to {0} available.", root.getVersion());
return 0;
}
@Command(name = "check", usageHelpAutoWidth = true, mixinStandardHelpOptions = true, description = "Check for update to this application.")
public static class Check implements Callable {
@Spec
CommandSpec spec;
@Override
public Integer call() throws Exception {
JadaptiveCommand root = JadaptiveCommand.getRootCommand(spec);
var updateService = root.getUpdateService();
var terminal = root.getTerminal();
updateService.checkForUpdate();
if(updateService.isNeedsUpdating()) {
terminal.messageln("Updates available [{0} -> {1}]", root.getVersion(), updateService.getAvailableVersion());
}
else
terminal.messageln("No update to {0} available.", root.getVersion());
return 0;
}
}
@Command(name = "phase", usageHelpAutoWidth = true, mixinStandardHelpOptions = true, description = "Set or show the current update setOrGetPhase.")
public static class SetOrGetPhase implements Callable {
@Spec
CommandSpec spec;
@Parameters(arity = "0..1", description = "Phase to set. If ommitted, current phase will be shown.")
Optional phase;
@Override
public Integer call() throws Exception {
JadaptiveCommand root = JadaptiveCommand.getRootCommand(spec);
var terminal = root.getTerminal();
phase.ifPresentOrElse(p -> root.getUpdateService().getContext().setPhase(p),
() -> terminal.messageln("Current phase: {0}", root.getUpdateService().getContext().getPhase()));
return 0;
}
}
@Command(name = "list-phases", usageHelpAutoWidth = true, mixinStandardHelpOptions = true, description = "Set or show the current update setOrGetPhase.")
public static class ListPhases implements Callable {
@Spec
CommandSpec spec;
@Override
public Integer call() throws Exception {
JadaptiveCommand root = JadaptiveCommand.getRootCommand(spec);
var terminal = root.getTerminal();
for(var p : root.getUpdateService().getPhases()) {
terminal.messageln(p.name());
}
return 0;
}
}
}