-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: download translations alias (#862)
- Loading branch information
1 parent
c22e3c4
commit 3ec7e64
Showing
6 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/main/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.crowdin.cli.commands.picocli; | ||
|
||
import com.crowdin.cli.client.ProjectClient; | ||
import com.crowdin.cli.commands.Actions; | ||
import com.crowdin.cli.commands.NewAction; | ||
import com.crowdin.cli.commands.functionality.FsFiles; | ||
import com.crowdin.cli.properties.ParamsWithFiles; | ||
import com.crowdin.cli.properties.PropertiesWithFiles; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Command( | ||
name = CommandNames.TRANSLATIONS, | ||
sortOptions = false | ||
) | ||
public class DownloadTranslationsSubcommand extends ActCommandWithFiles { | ||
|
||
@CommandLine.Option(names = {"-b", "--branch"}, descriptionKey = "branch", paramLabel = "...", order = -2) | ||
protected String branchName; | ||
|
||
@CommandLine.Option(names = {"--ignore-match"}, descriptionKey = "crowdin.download.ignore-match", order = -2) | ||
protected boolean ignoreMatch; | ||
|
||
@CommandLine.Option(names = {"-l", "--language"}, descriptionKey = "crowdin.download.language", paramLabel = "...", order = -2) | ||
protected List<String> languageIds; | ||
|
||
@CommandLine.Option(names = {"-e", "--exclude-language"}, descriptionKey = "crowdin.download.exclude-language", paramLabel = "...", order = -2) | ||
protected List<String> excludeLanguageIds; | ||
|
||
@CommandLine.Option(names = {"--pseudo"}, descriptionKey = "crowdin.download.pseudo", order = -2) | ||
protected boolean pseudo; | ||
|
||
@CommandLine.Option(names = {"--skip-untranslated-strings"}, descriptionKey = "params.skipUntranslatedStrings", order = -2) | ||
protected Boolean skipTranslatedOnly; | ||
|
||
@CommandLine.Option(names = {"--skip-untranslated-files"}, descriptionKey = "params.skipUntranslatedFiles", order = -2) | ||
protected Boolean skipUntranslatedFiles; | ||
|
||
@CommandLine.Option(names = {"--export-only-approved"}, descriptionKey = "params.exportOnlyApproved", order = -2) | ||
protected Boolean exportApprovedOnly; | ||
|
||
@CommandLine.Option(names = {"--keep-archive"}, descriptionKey = "params.keepArchive", order = -2) | ||
protected boolean keepArchive; | ||
|
||
@CommandLine.Option(names = {"--all"}, descriptionKey = "crowdin.download.all", order = -2) | ||
protected boolean all; | ||
|
||
@CommandLine.Option(names = {"--dryrun"}, descriptionKey = "dryrun") | ||
protected boolean dryrun; | ||
|
||
@CommandLine.Option(names = {"--tree"}, descriptionKey = "tree.dryrun") | ||
protected boolean treeView; | ||
|
||
@CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain") | ||
protected boolean plainView; | ||
|
||
@Override | ||
protected NewAction<PropertiesWithFiles, ProjectClient> getAction(Actions actions) { | ||
return (dryrun) | ||
? actions.listTranslations(noProgress, treeView, false, plainView, all, true, false) | ||
: actions.download(new FsFiles(), noProgress, languageIds, excludeLanguageIds, pseudo, branchName, ignoreMatch, isVerbose, plainView, all, keepArchive); | ||
} | ||
|
||
@Override | ||
protected boolean isAnsi() { | ||
return super.isAnsi() && !plainView; | ||
} | ||
|
||
@Override | ||
protected void updateParams(ParamsWithFiles params) { | ||
params.setExportOptions(skipTranslatedOnly, skipUntranslatedFiles, exportApprovedOnly); | ||
} | ||
|
||
@Override | ||
protected List<String> checkOptions() { | ||
List<String> errors = new ArrayList<>(); | ||
if (languageIds != null && excludeLanguageIds != null) { | ||
errors.add(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict")); | ||
} | ||
return errors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/test/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.crowdin.cli.commands.picocli; | ||
|
||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static com.crowdin.cli.commands.picocli.GenericCommand.RESOURCE_BUNDLE; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.Mockito.verify; | ||
|
||
class DownloadTranslationsSubcommandTest extends PicocliTestUtils { | ||
|
||
@Test | ||
public void testDownload() { | ||
this.execute(CommandNames.DOWNLOAD, CommandNames.TRANSLATIONS, "--debug"); | ||
verify(actionsMock) | ||
.download(any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()); | ||
this.check(true); | ||
} | ||
|
||
@Test | ||
public void testDownloadDryrun() { | ||
this.execute(CommandNames.DOWNLOAD, CommandNames.TRANSLATIONS, "--dryrun"); | ||
verify(actionsMock) | ||
.listTranslations(anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()); | ||
this.check(true); | ||
} | ||
|
||
@Test | ||
public void testSubCommandCheckInvalidOptions() { | ||
DownloadTranslationsSubcommand downloadSubcommand = new DownloadTranslationsSubcommand(); | ||
downloadSubcommand.languageIds = Arrays.asList("uk", "es-ES"); | ||
downloadSubcommand.excludeLanguageIds = Arrays.asList("en"); | ||
List<String> errors = downloadSubcommand.checkOptions(); | ||
assertThat(errors, Matchers.equalTo(Arrays.asList(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict")))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters