Skip to content

Commit cf808e5

Browse files
Add command-line help to all tools.
Unify naming of warc-file arguments.
1 parent b4a631b commit cf808e5

File tree

11 files changed

+46
-7
lines changed

11 files changed

+46
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ Create a new file containing only html responses with status 200:
153153

154154
java -jar jwarc.jar filter ':status == 200 && http:content-type =~ "text/html(;.*)?"' example.warc > pages.warc
155155

156+
All available tools are listed per
157+
158+
java -jar jwarc.jar
159+
160+
and every tool provides a command-line help if called with the option `--help`.
161+
156162
## API Quick Reference
157163

158164
See the [javadoc](https://www.javadoc.io/doc/org.netpreserve/jwarc) for more details.

src/org/netpreserve/jwarc/tools/ExtractTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private static void writeBody(WritableByteChannel out, ReadableByteChannel body)
7979

8080
private static void usage(int exitValue) {
8181
System.err.println();
82-
System.err.println("ExtractTool [-h] [--payload | --headers] filename offset ...");
82+
System.err.println("ExtractTool [-h] [--payload | --headers] warc-file offset...");
8383
System.err.println();
8484
System.err.println("Options:");
8585
System.err.println();

src/org/netpreserve/jwarc/tools/FilterTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class FilterTool {
1010
public static void main(String[] args) throws Exception {
1111
try {
1212
String[] files;
13-
if (args.length == 0) {
14-
System.err.println("Usage: jwarc filter <expression> [warc-file]...");
13+
if (args.length == 0 || Utils.hasHelpFlag(args)) {
14+
System.err.println("Usage: jwarc filter <expression> [warc-file...]");
1515
System.err.println(" e.g. jwarc filter 'warc-type == \"response\" && http:content-type =~ \"image/.*\" && :status == 200' example.warc");
1616
System.exit(1);
1717
return;

src/org/netpreserve/jwarc/tools/ListTool.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
import java.nio.file.Paths;
77

88
public class ListTool {
9+
910
public static void main(String[] args) throws IOException {
11+
Utils.showUsage(args, 1, ListTool.class, "warc-file...", "List records in WARC file(s)");
1012
for (String arg : args) {
1113
try (WarcReader reader = new WarcReader(Paths.get(arg))) {
1214
for (WarcRecord record : reader) {

src/org/netpreserve/jwarc/tools/RecordTool.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
public class RecordTool {
1313
public static void main(String[] args) throws Exception {
14+
Utils.showUsage(args, 1, RecordTool.class, "uri...",
15+
"Record pages and page dependencies using headless Chrome or the browser executable"
16+
+ "\ndefined by the environment variable BROWSER (default: \"google-chrome\")."
17+
+ "\n\nWARC output is written to stdout.");
1418
try (ServerSocket socket = new ServerSocket(0, -1, InetAddress.getLoopbackAddress())) {
1519
WarcRecorder recorder = new WarcRecorder(socket, new WarcWriter(System.out));
1620
new Thread(recorder::listen).start();

src/org/netpreserve/jwarc/tools/SavebackTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static void main(String[] args) throws IOException {
5757
}
5858

5959
private static void usage() {
60-
System.err.println("Usage: jwarc saveback wayback-url ...");
60+
System.err.println("Usage: jwarc saveback wayback-url...");
6161
System.err.println("Reconstructs WARC records from wayback or pywb replayed pages");
6262
System.err.println("Intended to be used with the id_ option: .../wayback/20060101010000id_/http://example.org/");
6363
System.err.println();

src/org/netpreserve/jwarc/tools/ScreenshotTool.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313

1414
public class ScreenshotTool {
1515
public static void main(String[] args) throws Exception {
16+
Utils.showUsage(args, 1, ScreenshotTool.class, "warc-file...",
17+
"Take a screenshot of each page in the given WARCs."
18+
+ "\n\nThe browser executable defined by the environment variable BROWSER"
19+
+ "\nis used to take the screenshots (default: \"google-chrome\")."
20+
+ "\n\nWARC output is written to stdout.");
1621
List<Path> warcs = Stream.of(args).map(Paths::get).collect(Collectors.toList());
1722
try (WarcWriter warcWriter = new WarcWriter(System.out);
1823
WarcRenderer renderer = new WarcRenderer(new CaptureIndex(warcs))) {

src/org/netpreserve/jwarc/tools/ServeTool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
public class ServeTool {
1313
public static void main(String[] args) throws Exception {
14-
if (args.length == 0) {
14+
if (args.length == 0 || Utils.hasHelpFlag(args)) {
1515
System.err.println("Usage: WarcTool serve <warc-files>");
1616
System.err.println("Obeys environment variable PORT.");
1717
System.exit(1);

src/org/netpreserve/jwarc/tools/Utils.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.net.URL;
6+
import java.util.Arrays;
67
import java.util.Properties;
78

89
class Utils {
@@ -18,4 +19,23 @@ static String getJwarcVersion() {
1819
}
1920
return properties.getProperty("version");
2021
}
22+
23+
static boolean hasHelpFlag(String[] args) {
24+
return Arrays.stream(args).anyMatch(arg -> arg.equals("-h") || arg.equals("--help") || arg.equals("-?"));
25+
}
26+
27+
static void showUsage(String[] args, int minArgs, Class<?> cls, String arguments, String description) {
28+
if (hasHelpFlag(args) || args.length < minArgs) {
29+
System.err.println("");
30+
System.err.println(cls.getSimpleName() + " [-h] " + arguments);
31+
System.err.println("");
32+
System.err.println(description);
33+
System.err.println("");
34+
System.err.println("Options:");
35+
System.err.println("");
36+
System.err.println(" -h / --help\tshow usage message and exit");
37+
System.err.println("");
38+
System.exit(0);
39+
}
40+
}
2141
}

src/org/netpreserve/jwarc/tools/ValidateTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import java.util.function.Consumer;
2424

2525

26-
public class ValidateTool extends WarcTool {
26+
public class ValidateTool {
2727

2828
private final static MediaType DNS = MediaType.parse("text/dns");
2929

@@ -294,7 +294,7 @@ boolean validate(Path warcFile) {
294294

295295
private static void usage(int exitValue) {
296296
System.err.println("");
297-
System.err.println("ValidateTool [-h] [-v] filename...");
297+
System.err.println("ValidateTool [-h] [-v] warc-file...");
298298
System.err.println("");
299299
System.err.println("Options:");
300300
System.err.println("");

0 commit comments

Comments
 (0)