Skip to content

Commit

Permalink
remove commons-cli dependency from integrations (airbytehq#22525)
Browse files Browse the repository at this point in the history
* remove commons-cli dependency from integrations

* re-add commons-cli dependency, used in other places
  • Loading branch information
colesnodgrass authored and danidelvalle-frontiers committed Feb 9, 2023
1 parent b04321a commit 91b8776
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 58 deletions.
18 changes: 0 additions & 18 deletions airbyte-commons-cli/src/main/java/io/airbyte/commons/cli/Clis.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,43 @@

// 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.
*/
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);
Expand Down

0 comments on commit 91b8776

Please sign in to comment.