in monitoring/cloud-client/src/main/java/com/example/monitoring/Snippets.java [440:525]
void handleCommandLine(String commandLine) throws IOException {
String[] args = commandLine.split("\\s+");
if (args.length < 1) {
throw new IllegalArgumentException("not enough args");
}
String command = args[0];
switch (command) {
case "new-metric-descriptor":
// Everything after the first whitespace token is interpreted to be the description.
args = commandLine.split("\\s+", 2);
if (args.length != 2) {
throw new IllegalArgumentException("usage: <type>");
}
// Set created to now() and done to false.
createMetricDescriptor(args[1]);
System.out.println("Metric descriptor created");
break;
case "list-metric-descriptors":
args = commandLine.split("\\s+", 2);
if (args.length != 1) {
throw new IllegalArgumentException("usage: no arguments");
}
listMetricDescriptors();
break;
case "list-monitored-resources":
args = commandLine.split("\\s+", 2);
if (args.length != 1) {
throw new IllegalArgumentException("usage: no arguments");
}
listMonitoredResources();
break;
case "get-descriptor-resource":
args = commandLine.split("\\s+", 2);
if (args.length != 2) {
throw new IllegalArgumentException("usage: <type>");
}
describeMetricResources(args[1]);
break;
case "delete-metric-descriptor":
args = commandLine.split("\\s+", 2);
if (args.length != 2) {
throw new IllegalArgumentException("usage: <type>");
}
deleteMetricDescriptor(args[1]);
break;
case "write-time-series":
args = commandLine.split("\\s+", 2);
if (args.length != 1) {
throw new IllegalArgumentException("usage: no arguments");
}
writeTimeSeries();
break;
case "list-time-series-header":
args = commandLine.split("\\s+", 2);
if (args.length != 1) {
throw new IllegalArgumentException("usage: no arguments");
}
listTimeSeriesHeaders();
break;
case "list-time-series":
args = commandLine.split("\\s+", 2);
if (args.length != 2) {
throw new IllegalArgumentException("usage: <filter>");
}
listTimeSeries(args[1]);
break;
case "list-aggregate":
args = commandLine.split("\\s+", 2);
if (args.length != 1) {
throw new IllegalArgumentException("usage: no arguments");
}
listTimeSeriesAggregrate();
break;
case "list-reduce":
args = commandLine.split("\\s+", 2);
if (args.length != 1) {
throw new IllegalArgumentException("usage: no arguments");
}
listTimeSeriesReduce();
break;
default:
throw new IllegalArgumentException("unrecognized command: " + command);
}
}