Skip to content

Commit 149dd1d

Browse files
committed
Add help command
1 parent 8cb8be8 commit 149dd1d

File tree

6 files changed

+142
-2
lines changed

6 files changed

+142
-2
lines changed

src/config/config_geom.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@
1717
"allPublicFields": true,
1818
"allDeclaredFields": true
1919
},
20+
{
21+
"name": "org.geometrycommands.HelpCommand",
22+
"allDeclaredConstructors": true,
23+
"allPublicConstructors": true,
24+
"allDeclaredMethods": true,
25+
"allPublicMethods": true,
26+
"allPublicFields": true,
27+
"allDeclaredFields": true
28+
},
29+
{
30+
"name": "org.geometrycommands.HelpCommand$HelpOptions",
31+
"allDeclaredConstructors": true,
32+
"allPublicConstructors": true,
33+
"allDeclaredMethods": true,
34+
"allPublicMethods": true,
35+
"allPublicFields": true,
36+
"allDeclaredFields": true
37+
},
2038
{
2139
"name": "org.geometrycommands.VersionCommand",
2240
"allDeclaredConstructors": true,
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package org.geometrycommands;
2+
3+
import org.geometrycommands.HelpCommand.HelpOptions;
4+
5+
import java.io.Reader;
6+
import java.io.Writer;
7+
8+
public class HelpCommand implements Command<HelpOptions> {
9+
10+
/**
11+
* Get the Command's name
12+
*
13+
* @return The Command's name
14+
*/
15+
@Override
16+
public String getName() {
17+
return "help";
18+
}
19+
20+
/**
21+
* Get the description of what the Command does
22+
*
23+
* @return The description of what the Command does
24+
*/
25+
@Override
26+
public String getDescription() {
27+
return "Get help";
28+
}
29+
30+
/**
31+
* Get a new Options
32+
*
33+
* @return A new Options
34+
*/
35+
@Override
36+
public HelpOptions getOptions() {
37+
return new HelpOptions();
38+
}
39+
40+
/**
41+
* Execute this Command with the given Options
42+
*
43+
* @param options The Options
44+
* @param reader The java.io.Reader
45+
* @param writer The java.io.Writer
46+
* @throws Exception if an error occurs
47+
*/
48+
@Override
49+
public void execute(HelpOptions options, Reader reader, Writer writer) throws Exception {
50+
final String newLine = System.getProperty("line.separator");
51+
StringBuilder builder = new StringBuilder();
52+
builder.append("Usage: geom <command> <args>").append(newLine);
53+
builder.append(newLine);
54+
builder.append("'geom list' lists available commands.").append(newLine);
55+
builder.append(newLine);
56+
builder.append("Use 'geom <command> --help' for help using a specific command.");
57+
writer.write(builder.toString());
58+
}
59+
60+
public static class HelpOptions extends Options {
61+
}
62+
63+
}

src/main/resources/META-INF/services/org.geometrycommands.Command

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,5 @@ org.geometrycommands.TranslateCommand
9696
org.geometrycommands.UnionCommand
9797
org.geometrycommands.VoronoiDiagramCommand
9898
org.geometrycommands.WithinCommand
99-
org.geometrycommands.VersionCommand
99+
org.geometrycommands.VersionCommand
100+
org.geometrycommands.HelpCommand

src/man/geom-help.1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.TH "geom-help" "1" "4 May 2012" "version 0.1"
2+
.SH NAME
3+
geom help
4+
.SH DESCRIPTION
5+
Get help
6+
.SH USAGE
7+
geom help
8+
.SH OPTIONS
9+
--help : Print help message
10+
.PP
11+
--web-help : Open help in a web browser
12+
.PP

src/shell/geom_bash_comp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ _geom()
55
local line=${COMP_LINE}
66
COMPREPLY=()
77
if [[ "$line" == *"geom " ]]; then
8-
COMPREPLY=($(compgen -W 'angle arc arcpoly area asciiart boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linedissolve linemerge list locatepoint mincircle minclearance mindiameter minrect narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union version voronoi within' -- $cur))
8+
COMPREPLY=($(compgen -W 'angle arc arcpoly area asciiart boundary buffer centroid closelinestring combine contains convexHull coordinates count countpoints coveredby covers crosses delaunay densify difference dimension disjoint distance distanceline draw drawbase64 dump ellipse endpoint envelope equals fromwkb get grid hausdorffdistance help interiorpoint interpolatepoint intersection intersects isccw isclosed isempty isrectangle isring issimple isvalid iswithindistance kochsnowflake linedissolve linemerge list locatepoint mincircle minclearance mindiameter minrect narrow nearestpoints node normalize octagonalenvelope overlaps placepoint pointatangle polygonize project random randomwalk rectangle reduceprecision reflect relate reverse rotate scale shear sierpinskicarpet similarity simplify sinestar slice snap split spoke squircle startpoint subline supercircle symdifference text touches towkb translate type union version voronoi within' -- $cur))
99
elif [[ "$line" == *"geom angle "* ]]; then
1010
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -o --otherGeometry -t --type' -- $cur))
1111
elif [[ "$line" == *"geom arc "* ]]; then
@@ -78,6 +78,8 @@ _geom()
7878
COMPREPLY=($(compgen -W '--help --web-help -c --columns -g --geometry -r --rows' -- $cur))
7979
elif [[ "$line" == *"geom hausdorffdistance "* ]]; then
8080
COMPREPLY=($(compgen -W '--help --web-help -g --geometry -o --otherGeometry' -- $cur))
81+
elif [[ "$line" == *"geom help "* ]]; then
82+
COMPREPLY=($(compgen -W '--help --web-help' -- $cur))
8183
elif [[ "$line" == *"geom interiorpoint "* ]]; then
8284
COMPREPLY=($(compgen -W '--help --web-help -g --geometry' -- $cur))
8385
elif [[ "$line" == *"geom interpolatepoint "* ]]; then
@@ -314,6 +316,9 @@ _geom()
314316
if [[ "hausdorffdistance" == "$nm"* ]]; then
315317
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'hausdorffdistance'))
316318
fi
319+
if [[ "help" == "$nm"* ]]; then
320+
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'help'))
321+
fi
317322
if [[ "interiorpoint" == "$nm"* ]]; then
318323
COMPREPLY=("${COMPREPLY[@]}" $(compgen -W 'interiorpoint'))
319324
fi
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.geometrycommands;
2+
3+
import org.geometrycommands.HelpCommand.HelpOptions;
4+
import org.junit.Test;
5+
6+
import java.io.*;
7+
import java.util.Properties;
8+
9+
import static org.junit.Assert.assertEquals;
10+
11+
public class HelpCommandTest extends BaseTest {
12+
13+
@Test
14+
public void execute() throws Exception {
15+
HelpOptions options = new HelpOptions();
16+
Reader reader = new StringReader("");
17+
StringWriter writer = new StringWriter();
18+
19+
HelpCommand command = new HelpCommand();
20+
command.execute(options, reader, writer);
21+
assertEquals(getExpectedHelp(), writer.getBuffer().toString());
22+
}
23+
24+
@Test
25+
public void run() throws Exception {
26+
String result = runApp(new String[]{
27+
"Help"
28+
}, null);
29+
assertEquals(getExpectedHelp(), result);
30+
}
31+
32+
private String getExpectedHelp() throws IOException {
33+
String expectedHelp = "Usage: geom <command> <args>" + NEW_LINE +
34+
NEW_LINE +
35+
"'geom list' lists available commands." + NEW_LINE +
36+
NEW_LINE +
37+
"Use 'geom <command> --help' for help using a specific command.";
38+
return expectedHelp;
39+
}
40+
41+
}

0 commit comments

Comments
 (0)