Skip to content

Commit 0d3eb34

Browse files
committed
WIP
1 parent 7068fc9 commit 0d3eb34

9 files changed

Lines changed: 150 additions & 107 deletions

File tree

src/main/java/act/cli/builtin/Exit.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ private Object readResolve() {
2626
}
2727

2828
@Override
29-
public $.T2<String, String> commandLine(String commandName) {
30-
return $.T2(commandName, "exit the console");
29+
public $.T2<String, String> commandLine() {
30+
return $.T2("exit", "exit the console");
3131
}
3232

3333
@Override

src/main/java/act/cli/builtin/Help.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ private void list(String search, String label, String fmt, List<String> commands
7070
}
7171
for (String cmd : commands) {
7272
CliHandler handler = dispatcher.handler(cmd);
73-
T2<String, String> commandLine = handler.commandLine(cmd);
73+
T2<String, String> commandLine = handler.commandLine();
7474
if (noSearch || commandLine._1.contains(search)) {
7575
lines.add(S.fmt(fmt, cmd, commandLine._2));
7676
}
@@ -96,7 +96,7 @@ public boolean showHelp(String command, CliContext context) {
9696
List<String> lines = C.newList();
9797

9898
List<String> names = dispatcher.names(handler);
99-
T2<String, String> commandLine = handler.commandLine(command);
99+
T2<String, String> commandLine = handler.commandLine();
100100
lines.add("Usage: " + names.get(0));
101101
lines.add(commandLine._2);
102102

@@ -136,7 +136,7 @@ public boolean showHelp(String command, CliContext context) {
136136
}
137137

138138
@Override
139-
public T2<String, String> commandLine(String commandName) {
139+
public T2<String, String> commandLine() {
140140
return T2("help [options] [command]", "show help information");
141141
}
142142

src/main/java/act/cli/builtin/IterateCursor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ private Object readResolve() {
2929
}
3030

3131
@Override
32-
public $.T2<String, String> commandLine(String commandName) {
33-
return $.T2(commandName, "iterate through cursor");
32+
public $.T2<String, String> commandLine() {
33+
return $.T2("it", "iterate through cursor");
3434
}
3535

3636
@Override

src/main/java/act/cli/meta/CommandMethodMetaInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public String helpMsg() {
118118
* @return the command line
119119
* @see act.handler.CliHandler#commandLine(String)
120120
*/
121-
public $.T2<String, String> commandLine(String commandName, CommanderClassMetaInfo classMetaInfo, AppClassLoader classLoader) {
121+
public $.T2<String, String> commandLine(CommanderClassMetaInfo classMetaInfo, AppClassLoader classLoader) {
122122
boolean hasOptions = classMetaInfo.hasOption(classLoader);
123123
String firstArg = null;
124124
boolean hasMoreArgs = false;

src/main/java/act/data/Format.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package act.data;
2+
3+
/**
4+
* Specify the Date time format
5+
*/
6+
public @interface Format {
7+
/**
8+
* The date time format value. E.g
9+
*
10+
* * "yyyy-MM-dd"
11+
* * "dd/MM/yyyy HH:MM"
12+
*
13+
* @return the format string
14+
*/
15+
String value();
16+
}

src/main/java/act/handler/CliHandler.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ public interface CliHandler extends $.Function<CliContext, Void>, Destroyable {
3131
* <p>
3232
* <code>$.T2("help [options] [command]", "show help message")</code>
3333
* </p>
34-
* @param commandName the command name of the command.
35-
* This param is required because some command might be registered
36-
* using different alias
3734
* @return the command line
3835
*/
39-
$.T2<String, String> commandLine(String commandName);
36+
$.T2<String, String> commandLine();
4037

4138
/**
4239
* Returns the summary of the command. This is used to display the help information

src/main/java/act/handler/builtin/cli/CliHandlerProxy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public void handle(CliContext context) {
7676
}
7777

7878
@Override
79-
public $.T2<String, String> commandLine(String commandName) {
80-
return methodMetaInfo.commandLine(commandName, classMetaInfo, app.classLoader());
79+
public $.T2<String, String> commandLine() {
80+
return methodMetaInfo.commandLine(classMetaInfo, app.classLoader());
8181
}
8282

8383
@Override
Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
@import org.osgl.*, act.cli.meta.*
22
@args() {
3-
String cmd
4-
act.handler.CliHandler handler
5-
act.cli.CliDispatcher dispatcher
3+
String cmd
4+
act.handler.CliHandler handler
5+
act.cli.CliDispatcher dispatcher
66
}
77

8-
<h3>@cmd</h3>
8+
@{
9+
String title = cmd;
10+
String help = handler.commandLine()._2;
11+
if (s().notEmpty(help)) {
12+
title = help;
13+
}
14+
}
15+
16+
<h3>@title</h3>
917

1018
<p class="desc">
11-
@handler.summary()
19+
@handler.summary()
1220
</p>
1321

1422
<form action="/cmd" method="post">
15-
@for ($.Tuple<String, String> option: handler.options()) {
16-
<label>@option._1</label>
17-
<input type="hidden" name="cmd" value="@cmd">
18-
<input type="text" class="u-full-width" placeholder="@option._2" title="@option._2" name="@option._1">
19-
}
20-
<button type="button">Submit</button>
23+
<input type="hidden" name="cmd" value="@cmd">
24+
@for ($.Tuple
25+
<String
26+
, String> option: handler.options()) {
27+
<label>@option._1</label>
28+
<input type="text" class="u-full-width" placeholder="@option._2" title="@option._2" name="@option._1">
29+
}
30+
<button type="button">Submit</button>
2131
</form>
2232

2333
<h3>Result</h3>
2434
<pre id="result"></pre>
2535
<script>
26-
$('button').on('click', function() {
27-
$.post('/cmd', $('form').serialize(), function (txt) {
28-
$('#result').text(txt);
29-
} )
36+
$('button').on('click', function () {
37+
$.post('/cmd', $('form').serialize(), function (txt) {
38+
$('#result').text(txt);
3039
})
40+
})
3141
</script>

src/main/resources/rythm/act/controller/builtin/CliOverHttp/home.html

Lines changed: 98 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,94 +2,114 @@
22
@import org.osgl.Osgl
33
@section(moreStyles) {
44
<style>
5-
body {
6-
background-color: #333;
7-
color: #bbb;
8-
}
9-
#page-title {
10-
padding-top: 50px;
11-
padding-bottom: 20px;
12-
border-bottom: 1px solid #777;
13-
}
14-
dt {
15-
font-weight: bold;
16-
}
17-
dd {
18-
margin: 0;
19-
padding-left: 18px;
20-
}
21-
#command-nav {
22-
border-right: 1px solid #777;
23-
}
24-
.command {
25-
padding: 12px 10px 12px 20px;
26-
cursor: pointer;
27-
}
28-
.command:hover {
29-
background-color: #555;
30-
}
31-
.command.active {
32-
background-color: #777;
33-
color: #333
34-
}
35-
.hidden {display: none;}
5+
body {
6+
background-color: #333;
7+
color: #bbb;
8+
}
9+
10+
#page-title {
11+
padding-top: 50px;
12+
padding-bottom: 20px;
13+
border-bottom: 1px solid #777;
14+
}
15+
16+
dt {
17+
font-weight: bold;
18+
}
19+
20+
dd {
21+
margin: 0;
22+
padding-left: 18px;
23+
}
24+
25+
#command-nav {
26+
border-right: 1px solid #777;
27+
}
28+
29+
.command {
30+
padding: 12px 10px 12px 20px;
31+
cursor: pointer;
32+
}
33+
34+
.command:hover {
35+
background-color: #555;
36+
}
37+
38+
.command.active {
39+
background-color: #777;
40+
color: #333
41+
}
42+
43+
.hidden {
44+
display: none;
45+
}
46+
.button, button, input[type="submit"], input[type="reset"], input[type="button"] {
47+
color: #aaa
48+
}
49+
.button:hover, button:hover, input[type="submit"]:hover, input[type="reset"]:hover, input[type="button"]:hover,
50+
.button:focus, button:focus, input[type="submit"]:focus, input[type="reset"]:focus, input[type="button"]:focus {
51+
color: #eee
52+
}
3653
</style>
3754
}
3855
@args act.cli.CliDispatcher dispatcher
3956

40-
@def commandList(List<String> commandList) {
41-
<dl class="command-list">
57+
@def commandList(List
58+
<String> commandList) {
59+
<dl class="command-list">
4260
@for(String cmd: commandList) {
43-
@{
44-
act.handler.CliHandler handler = dispatcher.handler(cmd);
45-
Osgl.T2<String, String> commandLine = handler.commandLine(cmd);
46-
}
47-
<div class="command" data-cmd="@cmd">
48-
<dt>
49-
<i class="fa fa-wrench" aria-hidden="true"></i>&nbsp;@cmd
50-
</dt>
51-
<dd>
52-
@commandLine._2
53-
</dd>
54-
</div>
61+
@{
62+
act.handler.CliHandler handler = dispatcher.handler(cmd);
63+
Osgl.T2
64+
<String
65+
, String> commandLine = handler.commandLine();
66+
}
67+
<div class="command" data-cmd="@cmd">
68+
<dt>
69+
<i class="fa fa-wrench" aria-hidden="true"></i>&nbsp;@cmd
70+
</dt>
71+
<dd>
72+
@commandLine._2
73+
</dd>
74+
</div>
5575
} else {
56-
<span>No command found ...</span>
76+
<span>No command found ...</span>
5777
}
58-
</dl>
59-
}
78+
</dl>
79+
}
6080

61-
<div class="row">
62-
<h1 id="page-title">CLI Over HTTP</h1>
63-
</div>
64-
<div class="row">
65-
<div class="four columns" id="command-nav">
66-
<div id="app-commands">
67-
<h5>Application commands</h5>
68-
@commandList(dispatcher.applicationCommands())
69-
</div>
81+
<div class="row">
82+
<h1 id="page-title">CLI Over HTTP</h1>
83+
</div>
84+
<div class="row">
85+
<div class="four columns" id="command-nav">
86+
<div id="app-commands">
87+
<h5>Application commands</h5>
88+
@commandList(dispatcher.applicationCommands())
89+
</div>
7090

71-
<div id="sys-commands">
72-
<h5>System commands</h5>
73-
@commandList(dispatcher.systemCommands())
74-
</div>
75-
</div>
76-
<div id="detail" class="eight columns">
77-
<p>
78-
Click on the command list in the left navigation column to load command panel
79-
</p>
80-
</div>
91+
<div id="sys-commands">
92+
<h5>System commands</h5>
93+
@commandList(dispatcher.systemCommands())
94+
</div>
95+
</div>
96+
<div id="detail" class="eight columns">
97+
<p>
98+
Click on the command list in the left navigation column to load command panel
99+
</p>
81100
</div>
101+
</div>
82102

83-
@section(moreScripts){
84-
<script>
103+
@section(moreScripts){
104+
<script>
85105
var curCmd;
86-
$('div.command').click(function() {
87-
curCmd = $(this).data('cmd');
88-
$('div.command').removeClass('active');
89-
$(this).addClass('active');
90-
$.get('/cmd', {cmd: curCmd}, function(detail) {
91-
$('#detail').html(detail).removeClass('hidden')
92-
})
106+
$('div.command').click(function () {
107+
curCmd = $(this).data('cmd');
108+
$('div.command').removeClass('active');
109+
$(this).addClass('active');
110+
$.get('/cmd', {cmd: curCmd}, function (detail) {
111+
$('#detail').html(detail).removeClass('hidden')
112+
})
93113
})
94-
</script>
95-
}
114+
</script>
115+
}

0 commit comments

Comments
 (0)