]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.cli/src/org/argeo/cms/cli/CmsCommands.java
1 package org
.argeo
.cms
.cli
;
6 import org
.apache
.commons
.cli
.CommandLine
;
7 import org
.apache
.commons
.cli
.Option
;
8 import org
.apache
.commons
.cli
.Options
;
9 import org
.argeo
.api
.cli
.CommandsCli
;
10 import org
.argeo
.api
.cli
.DescribedCommand
;
11 import org
.argeo
.cms
.client
.CmsClient
;
12 import org
.argeo
.cms
.client
.WebSocketPing
;
14 /** Commands dealing with CMS. */
15 public class CmsCommands
extends CommandsCli
{
16 final static Option connectOption
= Option
.builder().option("c").longOpt("connect").desc("server to connect to")
17 .hasArg(true).build();
19 public CmsCommands(String commandName
) {
21 addCommand("ping", new Ping());
22 addCommand("get", new Get());
23 addCommand("status", new Status());
24 addCommand("event", new EventCommands("event"));
28 public String
getDescription() {
29 return "Utilities related to an Argeo CMS";
32 class Ping
implements DescribedCommand
<Void
> {
34 public Options
getOptions() {
35 Options options
= new Options();
36 options
.addOption(connectOption
);
41 public Void
apply(List
<String
> t
) {
42 CommandLine line
= toCommandLine(t
);
43 String uriArg
= line
.getOptionValue(connectOption
);
44 // TODO make it more robust (trailing /, etc.)
45 URI uri
= URI
.create(uriArg
);
46 if ("".equals(uri
.getPath())) {
47 uri
= URI
.create(uri
.toString() + "/cms/status/ping");
49 new WebSocketPing(uri
).run();
54 public String
getUsage() {
55 return "[ws|wss]://host:port/";
59 public String
getDescription() {
60 return "Test whether an Argeo CMS is available, without auhtentication";
65 class Get
implements DescribedCommand
<String
> {
68 public Options
getOptions() {
69 Options options
= new Options();
70 options
.addOption(connectOption
);
75 public String
apply(List
<String
> t
) {
76 CommandLine line
= toCommandLine(t
);
77 List
<String
> remaining
= line
.getArgList();
78 String additionalUri
= null;
79 if (remaining
.size() != 0) {
80 additionalUri
= remaining
.get(0);
83 String connectUri
= line
.getOptionValue(connectOption
);
84 CmsClient cmsClient
= new CmsClient(URI
.create(connectUri
));
85 return additionalUri
!= null ? cmsClient
.getAsString(URI
.create(additionalUri
)) : cmsClient
.getAsString();
89 public String
getUsage() {
94 public String
getDescription() {
95 return "Retrieve this URI as a string";
100 class Status
implements DescribedCommand
<String
> {
103 public Options
getOptions() {
104 Options options
= new Options();
105 options
.addOption(connectOption
);
110 public String
apply(List
<String
> t
) {
111 CommandLine line
= toCommandLine(t
);
112 String connectUri
= line
.getOptionValue(connectOption
);
113 CmsClient cmsClient
= new CmsClient(URI
.create(connectUri
));
114 return cmsClient
.getAsString(URI
.create("/cms/status"));
118 public String
getUsage() {
123 public String
getDescription() {
124 return "Retrieve the CMS status as a string";