]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org/argeo/cms/cli/CmsCommands.java
Prepare next development cycle
[lgpl/argeo-commons.git] / org / argeo / cms / cli / CmsCommands.java
1 package org.argeo.cms.cli;
2
3 import java.net.URI;
4 import java.util.List;
5
6 import org.apache.commons.cli.CommandLine;
7 import org.argeo.api.cli.CommandArgsException;
8 import org.argeo.api.cli.CommandsCli;
9 import org.argeo.api.cli.DescribedCommand;
10 import org.argeo.cms.client.WsPing;
11
12 public class CmsCommands extends CommandsCli {
13
14 public CmsCommands(String commandName) {
15 super(commandName);
16 addCommand("ping", new Ping());
17 }
18
19 @Override
20 public String getDescription() {
21 return "Utilities related to an Argeo CMS";
22 }
23
24 class Ping implements DescribedCommand<Void> {
25
26 @Override
27 public Void apply(List<String> t) {
28 CommandLine line = toCommandLine(t);
29 List<String> remaining = line.getArgList();
30 if (remaining.size() == 0) {
31 throw new CommandArgsException("There must be at least one argument");
32 }
33 String uriArg = remaining.get(0);
34 // TODO make it more robust (trailing /, etc.)
35 URI uri = URI.create(uriArg);
36 if ("".equals(uri.getPath())) {
37 uri = URI.create(uri.toString() + "/cms/status/ping");
38 }
39 new WsPing(uri).run();
40 return null;
41 }
42
43 @Override
44 public String getUsage() {
45 return "[ws|wss]://host:port/";
46 }
47
48 @Override
49 public String getDescription() {
50 return "Test whether an Argeo CMS is available, without auhtentication";
51 }
52
53 }
54 }