blob: 3b41bf93aa0aa6bcc9dbc1c5b0fa31438cc3c137 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
package derms.client;
import java.net.MalformedURLException;
public class ResponderClientCLI extends CLI {
public static final String usage = "Usage: java derms.client.ResponderClientCLI <FE host>";
private final ResponderClient client;
private ResponderClientCLI(String FEhost) throws MalformedURLException {
client = new ResponderClient(FEhost);
commands.put("add", new Add());
cmdDescriptions.add(new Description(
"add <resource ID> <resource type> <duration>",
"Add ad resource to the server"));
}
public static void main(String[] args) {
if (args.length < 1) {
System.err.println("Missing argument 'FE host'");
System.exit(1);
}
String FEhost = args[0];
try {
(new ResponderClientCLI(FEhost)).run();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
private class Add implements Command {
@Override
public void exec(String[] args) {
if (args.length < 3) {
System.out.println("invalid arguments for 'add'");
} else {
add(args[0], args[1], args[2]);
}
}
private void add(String resourceID, String resourceName, String durationStr) {
int duration = Integer.parseInt(durationStr);
if (duration < 0) {
throw new NumberFormatException("duration less than 0");
}
String response = client.addResource(resourceID, resourceName, duration);
System.out.println(response);
}
}
}
|