diff --git a/src/main/java/com/crowdin/cli/commands/picocli/DownloadSourcesSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/DownloadSourcesSubcommand.java index fe46ce5f..cebd9327 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/DownloadSourcesSubcommand.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/DownloadSourcesSubcommand.java @@ -9,7 +9,7 @@ import picocli.CommandLine; @CommandLine.Command( - name = "sources", + name = CommandNames.SOURCES, sortOptions = false ) public class DownloadSourcesSubcommand extends ActCommandWithFiles { diff --git a/src/main/java/com/crowdin/cli/commands/picocli/DownloadSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/DownloadSubcommand.java index 752e8324..3594aa00 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/DownloadSubcommand.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/DownloadSubcommand.java @@ -16,7 +16,8 @@ sortOptions = false, aliases = CommandNames.ALIAS_DOWNLOAD, subcommands = { - DownloadSourcesSubcommand.class + DownloadSourcesSubcommand.class, + DownloadTranslationsSubcommand.class } ) class DownloadSubcommand extends ActCommandWithFiles { diff --git a/src/main/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommand.java new file mode 100644 index 00000000..b974ae14 --- /dev/null +++ b/src/main/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommand.java @@ -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 languageIds; + + @CommandLine.Option(names = {"-e", "--exclude-language"}, descriptionKey = "crowdin.download.exclude-language", paramLabel = "...", order = -2) + protected List 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 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 checkOptions() { + List errors = new ArrayList<>(); + if (languageIds != null && excludeLanguageIds != null) { + errors.add(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict")); + } + return errors; + } +} diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index 4feaae4a..f712bf6c 100755 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -47,6 +47,9 @@ crowdin.download.exclude-language=Skip the language during download. Can be spec crowdin.download.pseudo=Download pseudo-localized translation files crowdin.download.all=Download files even if local sources are missing +crowdin.download.translations.usage.description=Download the latest translations from Crowdin to the specified place +crowdin.download.translations.usage.customSynopsis=@|fg(green) crowdin |@(@|fg(green) download|@|@|fg(green) pull|@) translations [CONFIG OPTIONS] [OPTIONS] + # CROWDIN DOWNLOAD SOURCES COMMAND crowdin.download.sources.usage.description=Download sources from Crowdin to the specified place crowdin.download.sources.usage.customSynopsis=@|fg(green) crowdin |@(@|fg(green) download|@|@|fg(green) pull|@) @|fg(green) sources|@ [CONFIG OPTIONS] [OPTIONS] diff --git a/src/test/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommandTest.java b/src/test/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommandTest.java new file mode 100644 index 00000000..eba52673 --- /dev/null +++ b/src/test/java/com/crowdin/cli/commands/picocli/DownloadTranslationsSubcommandTest.java @@ -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 errors = downloadSubcommand.checkOptions(); + assertThat(errors, Matchers.equalTo(Arrays.asList(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict")))); + } +} \ No newline at end of file diff --git a/website/mantemplates/crowdin-download-translations.adoc b/website/mantemplates/crowdin-download-translations.adoc index edf1cd09..9c2afa9b 100644 --- a/website/mantemplates/crowdin-download-translations.adoc +++ b/website/mantemplates/crowdin-download-translations.adoc @@ -1,5 +1,5 @@ :includedir: ../generated-picocli-docs -:command: crowdin-download +:command: crowdin-download-translations == crowdin download translations @@ -24,12 +24,12 @@ include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-footer] Download multiple languages: ---- -crowdin download -l de -l fr -l it -crowdin download --language=de --language=fr --language=it +crowdin download translations -l de -l fr -l it +crowdin download translations --language=de --language=fr --language=it ---- Download all translations even if the corresponding source files are missing locally: ---- -crowdin download --all +crowdin download translations --all ----