Skip to content

Commit ece45cb

Browse files
author
Vicky M
committed
Added help printout when no args provided
1 parent 205b20f commit ece45cb

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

file.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
<SenseBox:5cc58071facf70001a872bef> a <http://www.w3.org/ns/sosa/Platform>;
3+
<http://www.opengis.net/ont/geosparql#wktLiteral> "POINT(13.441607, 52.469905)", "POINT(13.4420608, 52.4705383)",
4+
"POINT(13.442437, 52.4705708)", "POINT(52.4705708, 13.442437)";
5+
<http://www.w3.org/ns/sosa/hosts> <Sensor:5cc58071facf70001a872bf0>, <Sensor:5cc58071facf70001a872bf1>;
6+
<http://www.w3.org/ns/sosa/resultTime> "2019-05-11T17:57:48.949Z", "2019-05-11T17:58:39.542Z",
7+
"2019-05-11T18:02:58.328Z", "2019-05-11T18:05:48.536Z", "2019-05-11T18:51:30.618Z",
8+
"2019-05-11T18:53:02.765Z" .
9+
10+
<Sensor:5cc58071facf70001a872bf1> a <http://www.w3.org/ns/sosa/Sensor>;
11+
<http://www.w3.org/2000/01/rdf-schema#label> "PM2.5" .
12+
13+
<Sensor:5cc58071facf70001a872bf0> a <http://www.w3.org/ns/sosa/Sensor>;
14+
<http://www.w3.org/2000/01/rdf-schema#label> "PM10" .

src/main/java/Main.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import org.apache.commons.cli.CommandLine;
2+
import org.apache.commons.cli.HelpFormatter;
23
import org.apache.commons.cli.MissingOptionException;
34
import org.apache.commons.cli.ParseException;
45

@@ -10,8 +11,9 @@
1011
public class Main {
1112
public static void main(String[] args) throws ParseException, IOException {
1213

14+
Config c = new Config();
1315
try {
14-
CommandLine config = new Config().parseArgs(args);
16+
CommandLine config = c.parseArgs(args);
1517

1618
if (config.hasOption("osm")) {
1719
new OpenSenseMapHandler().handleConfig(config);
@@ -20,8 +22,8 @@ public static void main(String[] args) throws ParseException, IOException {
2022
System.out.println("Please refer to the README.");
2123
}
2224
} catch (MissingOptionException e) {
23-
System.out.println("You are missing the following options: " + e.getMissingOptions());
24-
System.out.println("Please refer to the README.");
25+
System.out.println("How to use");
26+
c.printHelp();
2527
}
2628
}
2729
}

src/main/java/osm/util/OpenSenseMapHandler.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package osm.util;
22

33
import org.apache.commons.cli.CommandLine;
4+
import org.apache.commons.cli.HelpFormatter;
5+
import org.apache.commons.cli.Option;
6+
import org.apache.commons.cli.Options;
47
import org.eclipse.rdf4j.model.Statement;
58

69
import osm.models.Location;
@@ -15,6 +18,7 @@
1518
public class OpenSenseMapHandler {
1619

1720
public void handleConfig(CommandLine config) throws IOException {
21+
1822
SenseBox senseBox = OpenSenseMapApi.getSenseBox(config.getOptionValue("osm"));
1923

2024
List<Statement> statements = RdfConverter.convertSenseBoxToStatements(senseBox);

src/main/java/util/Config.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,16 @@ public Config() {
4747
.argName("/path/to/file.rdf")
4848
.desc("Path to output file.")
4949
.build());
50+
5051
}
5152

5253
public CommandLine parseArgs(String[] args) throws ParseException {
5354
return new DefaultParser().parse(options, args);
5455
}
56+
57+
public void printHelp() {
58+
HelpFormatter hf = new HelpFormatter();
59+
hf.printHelp("OSM to RDF Parser ", options);
60+
}
61+
5562
}

0 commit comments

Comments
 (0)