org.etlunit.cli.SleepCmd Maven / Gradle / Ivy
package org.etlunit.cli;
import org.clamshellcli.api.Command;
import org.clamshellcli.api.Configurator;
import org.clamshellcli.api.Context;
import org.clamshellcli.api.IOConsole;
import java.util.HashMap;
import java.util.Map;
public class SleepCmd implements Command {
private static final String NAMESPACE = "syscmd";
public static final String ACTION_NAME = "sleep";
public Object execute(Context ctx) {
IOConsole console = ctx.getIoConsole();
String [] inputLine = (String []) ctx.getValue(Context.KEY_COMMAND_LINE_ARGS);
try {
int time = Integer.parseInt(inputLine[0]);
while (time > 0) {
time--;
Thread.sleep(1000L);
console.writeOutput(".");
}
console.writeOutput(Configurator.VALUE_LINE_SEP);
} catch (NumberFormatException exc) {
console.writeOutput("Input string " + inputLine[0] + " is not a number" + Configurator.VALUE_LINE_SEP);
} catch (Exception exc) {
console.writeOutput(exc.toString() + Configurator.VALUE_LINE_SEP);
}
return null;
}
public void plug(Context plug) {
// no load-time setup needed
}
public Descriptor getDescriptor() {
return new Descriptor() {
public String getNamespace() {
return NAMESPACE;
}
public String getName() {
return ACTION_NAME;
}
public String getDescription() {
return "Sleeps for the specified number of seconds";
}
public String getUsage() {
return "Type 'time'";
}
public Map getArguments() {
Map map = new HashMap();
map.put("time", "Sleep time, in seconds");
return map;
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy