Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#310 - ignore version check for -h,-v and crowdin command w/o args #516

Merged
merged 4 commits into from
Dec 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static void main(String[] args) {
Actions actions = new CliActions();
PropertiesBuilders propertiesBuilders = new PropertiesBuilders();
int exitCode = picocliRunner.execute(actions, propertiesBuilders, args);
if (exitCode != -1 && !picocliRunner.hasMatchedArg("plain")) {
if (exitCode != -1 && picocliRunner.noneMatchArgs("--help", "--version", "plain") && args.length != 0) {
picocliRunner.execute(actions, propertiesBuilders, CommandNames.CHECK_NEW_VERSION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.crowdin.cli.utils.Utils;
import picocli.CommandLine;

import java.util.stream.Stream;

/**
* Facade singleton class that is used to run <a href="https://picocli.info">picocli framework</a>.
*/
Expand Down Expand Up @@ -45,6 +47,10 @@ public boolean hasMatchedArg(String name) {
return parseResult.hasMatchedOption(name);
}

public boolean noneMatchArgs(String... args) {
return Stream.of(args).noneMatch(this::hasMatchedArg);
}

private void init() {
rootCommand = new RootCommand();
CommandLine.Help.ColorScheme colorScheme = buildColorScheme();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ public void testHasMatchedArgs() {
assertTrue(picocliRunner.hasMatchedArg("verbose"));
}

@Test
public void testNoneMatchedArgs() {
PicocliRunner picocliRunner = PicocliRunner.getInstance();
picocliRunner.execute(actionsMock, propertiesBuildersMock, "--version");
assertFalse(picocliRunner.noneMatchArgs("version"));
assertFalse(picocliRunner.noneMatchArgs("--version"));
assertFalse(picocliRunner.noneMatchArgs("-V"));

picocliRunner.execute(actionsMock, propertiesBuildersMock, "--help");
assertFalse(picocliRunner.noneMatchArgs("help"));
assertFalse(picocliRunner.noneMatchArgs("--help"));
assertFalse(picocliRunner.noneMatchArgs("-h"));
}

@Test
public void testVersionProvider() throws Exception {
CommandLine.IVersionProvider versionProvider = new PicocliRunner.VersionProvider();
Expand Down