From 91b8776b0868743560f8eb5647df9662e4679890 Mon Sep 17 00:00:00 2001 From: Cole Snodgrass Date: Tue, 7 Feb 2023 14:17:46 -0800 Subject: [PATCH] remove commons-cli dependency from integrations (#22525) * remove commons-cli dependency from integrations * re-add commons-cli dependency, used in other places --- .../java/io/airbyte/commons/cli/Clis.java | 18 ------- .../java/io/airbyte/commons/cli/ClisTest.java | 18 ------- .../base/IntegrationCliParser.java | 52 +++++++++++-------- 3 files changed, 30 insertions(+), 58 deletions(-) diff --git a/airbyte-commons-cli/src/main/java/io/airbyte/commons/cli/Clis.java b/airbyte-commons-cli/src/main/java/io/airbyte/commons/cli/Clis.java index 623ef16631eb..1e2b1eb8ebf2 100644 --- a/airbyte-commons-cli/src/main/java/io/airbyte/commons/cli/Clis.java +++ b/airbyte-commons-cli/src/main/java/io/airbyte/commons/cli/Clis.java @@ -10,8 +10,6 @@ import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionGroup; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; @@ -49,22 +47,6 @@ public static CommandLine parse(final String[] args, final Options options) { return parse(args, options, new DefaultParser()); } - /** - * Provide a fluent interface for building an OptionsGroup. - * - * @param isRequired - is the option group required - * @param options - options in the option group - * @return the created option group. - */ - public static OptionGroup createOptionGroup(final boolean isRequired, final Option... options) { - final OptionGroup optionGroup = new OptionGroup(); - optionGroup.setRequired(isRequired); - for (final Option option : options) { - optionGroup.addOption(option); - } - return optionGroup; - } - public static CommandLineParser getRelaxedParser() { return new RelaxedParser(); } diff --git a/airbyte-commons-cli/src/test/java/io/airbyte/commons/cli/ClisTest.java b/airbyte-commons-cli/src/test/java/io/airbyte/commons/cli/ClisTest.java index f2a09b3a2379..d485b4cd3d40 100644 --- a/airbyte-commons-cli/src/test/java/io/airbyte/commons/cli/ClisTest.java +++ b/airbyte-commons-cli/src/test/java/io/airbyte/commons/cli/ClisTest.java @@ -10,7 +10,6 @@ import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Option; -import org.apache.commons.cli.OptionGroup; import org.apache.commons.cli.Options; import org.junit.jupiter.api.Test; @@ -19,23 +18,6 @@ class ClisTest { private static final String ALPHA = "alpha"; private static final String BETA = "beta"; - @Test - void testCreateOptionGroup() { - final Option optionA = new Option("a", ALPHA); - final Option optionB = new Option("b", BETA); - final OptionGroup optionGroupExpected = new OptionGroup(); - optionGroupExpected.addOption(optionA); - optionGroupExpected.addOption(optionB); - - final OptionGroup optionGroupActual = Clis.createOptionGroup( - false, - optionA, - optionB); - - // hack: OptionGroup does not define hashcode, so compare its string instead of the object itself. - assertEquals(optionGroupExpected.toString(), optionGroupActual.toString()); - } - @Test void testParse() { final Option optionA = Option.builder("a").required(true).hasArg(true).build(); diff --git a/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationCliParser.java b/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationCliParser.java index 59c2d9d214f6..cd1b7c8ddb58 100644 --- a/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationCliParser.java +++ b/airbyte-integrations/bases/base-java/src/main/java/io/airbyte/integrations/base/IntegrationCliParser.java @@ -18,6 +18,7 @@ // todo (cgardens) - use argparse4j.github.io instead of org.apache.commons.cli to leverage better // sub-parser support. + /** * Parses command line args to a type safe config object for each command type. */ @@ -25,28 +26,35 @@ public class IntegrationCliParser { private static final Logger LOGGER = LoggerFactory.getLogger(IntegrationCliParser.class); - private static final OptionGroup COMMAND_GROUP = Clis.createOptionGroup( - true, - Option.builder() - .longOpt(Command.SPEC.toString().toLowerCase()) - .desc("outputs the json configuration specification") - .build(), - Option.builder() - .longOpt(Command.CHECK.toString().toLowerCase()) - .desc("checks the config can be used to connect") - .build(), - Option.builder() - .longOpt(Command.DISCOVER.toString().toLowerCase()) - .desc("outputs a catalog describing the source's catalog") - .build(), - Option.builder() - .longOpt(Command.READ.toString().toLowerCase()) - .desc("reads the source and outputs messages to STDOUT") - .build(), - Option.builder() - .longOpt(Command.WRITE.toString().toLowerCase()) - .desc("writes messages from STDIN to the integration") - .build()); + private static final OptionGroup COMMAND_GROUP; + + static { + final var optionGroup = new OptionGroup(); + optionGroup.setRequired(true); + + optionGroup.addOption(Option.builder() + .longOpt(Command.SPEC.toString().toLowerCase()) + .desc("outputs the json configuration specification") + .build()); + optionGroup.addOption(Option.builder() + .longOpt(Command.CHECK.toString().toLowerCase()) + .desc("checks the config can be used to connect") + .build()); + optionGroup.addOption(Option.builder() + .longOpt(Command.DISCOVER.toString().toLowerCase()) + .desc("outputs a catalog describing the source's catalog") + .build()); + optionGroup.addOption(Option.builder() + .longOpt(Command.READ.toString().toLowerCase()) + .desc("reads the source and outputs messages to STDOUT") + .build()); + optionGroup.addOption(Option.builder() + .longOpt(Command.WRITE.toString().toLowerCase()) + .desc("writes messages from STDIN to the integration") + .build()); + + COMMAND_GROUP = optionGroup; + } public IntegrationConfig parse(final String[] args) { final Command command = parseCommand(args);