From a6ad5251973c39c976434d3c2a4304487163b81e Mon Sep 17 00:00:00 2001 From: zzz Date: Thu, 26 May 2022 11:57:34 -0400 Subject: [PATCH] Addressbook: Add CLI --- apps/addressbook/build.xml | 9 +++- .../src/net/i2p/addressbook/CommandLine.java | 42 +++++++++++++++++++ .../net/i2p/addressbook/HostTxtParser.java | 4 +- 3 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 apps/addressbook/java/src/net/i2p/addressbook/CommandLine.java diff --git a/apps/addressbook/build.xml b/apps/addressbook/build.xml index 67feb3ca0..b02dc2409 100644 --- a/apps/addressbook/build.xml +++ b/apps/addressbook/build.xml @@ -9,6 +9,7 @@ + @@ -57,8 +58,14 @@ - + + + + + + + diff --git a/apps/addressbook/java/src/net/i2p/addressbook/CommandLine.java b/apps/addressbook/java/src/net/i2p/addressbook/CommandLine.java new file mode 100644 index 000000000..7a33a6ede --- /dev/null +++ b/apps/addressbook/java/src/net/i2p/addressbook/CommandLine.java @@ -0,0 +1,42 @@ +package net.i2p.addressbook; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.i2p.CoreVersion; + +/** + * Simple command line access to various utilities. + * Not a public API. Subject to change. + * Apps and plugins should use specific classes. + * + * @since 0.9.55 + */ +public class CommandLine extends net.i2p.util.CommandLine { + + protected static final List ACLASSES = Arrays.asList(new String[] { + "net.i2p.addressbook.HostTxtParser", + "net.i2p.router.naming.BlockfileNamingService", + "net.metanotion.io.block.BlockFile", + }); + + protected CommandLine() {} + + public static void main(String args[]) { + List classes = new ArrayList(ACLASSES.size() + CLASSES.size()); + classes.addAll(ACLASSES); + classes.addAll(CLASSES); + if (args.length > 0) { + exec(args, classes); + } + usage(classes); + System.exit(1); + } + + private static void usage(List classes) { + System.err.println("I2P Address book version " + CoreVersion.VERSION + '\n' + + "USAGE: java -jar /path/to/addressbook.jar command [args]"); + printCommands(classes); + } +} diff --git a/apps/addressbook/java/src/net/i2p/addressbook/HostTxtParser.java b/apps/addressbook/java/src/net/i2p/addressbook/HostTxtParser.java index bfdb55fc7..bf7686231 100644 --- a/apps/addressbook/java/src/net/i2p/addressbook/HostTxtParser.java +++ b/apps/addressbook/java/src/net/i2p/addressbook/HostTxtParser.java @@ -25,9 +25,9 @@ import net.i2p.util.SystemVersion; * Utility class providing methods to parse and write files in a hosts.txt file * format, and subscription file format. * - * @since 0.9.26 modified from ConfigParser + * @since 0.9.26 modified from ConfigParser, public since 0.9.55 for CLI */ -class HostTxtParser { +public class HostTxtParser { private static final boolean isWindows = SystemVersion.isWindows();