|
| 1 | +package com.crowdin.cli.commands.picocli; |
| 2 | + |
| 3 | +import com.crowdin.cli.client.ProjectClient; |
| 4 | +import com.crowdin.cli.commands.Actions; |
| 5 | +import com.crowdin.cli.commands.NewAction; |
| 6 | +import com.crowdin.cli.commands.functionality.FsFiles; |
| 7 | +import com.crowdin.cli.properties.ParamsWithFiles; |
| 8 | +import com.crowdin.cli.properties.PropertiesWithFiles; |
| 9 | +import picocli.CommandLine; |
| 10 | +import picocli.CommandLine.Command; |
| 11 | + |
| 12 | +import java.util.ArrayList; |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +@Command( |
| 16 | + name = CommandNames.TRANSLATIONS, |
| 17 | + sortOptions = false |
| 18 | +) |
| 19 | +public class DownloadTranslationsSubcommand extends ActCommandWithFiles { |
| 20 | + |
| 21 | + @CommandLine.Option(names = {"-b", "--branch"}, descriptionKey = "branch", paramLabel = "...", order = -2) |
| 22 | + protected String branchName; |
| 23 | + |
| 24 | + @CommandLine.Option(names = {"--ignore-match"}, descriptionKey = "crowdin.download.ignore-match", order = -2) |
| 25 | + protected boolean ignoreMatch; |
| 26 | + |
| 27 | + @CommandLine.Option(names = {"-l", "--language"}, descriptionKey = "crowdin.download.language", paramLabel = "...", order = -2) |
| 28 | + protected List<String> languageIds; |
| 29 | + |
| 30 | + @CommandLine.Option(names = {"-e", "--exclude-language"}, descriptionKey = "crowdin.download.exclude-language", paramLabel = "...", order = -2) |
| 31 | + protected List<String> excludeLanguageIds; |
| 32 | + |
| 33 | + @CommandLine.Option(names = {"--pseudo"}, descriptionKey = "crowdin.download.pseudo", order = -2) |
| 34 | + protected boolean pseudo; |
| 35 | + |
| 36 | + @CommandLine.Option(names = {"--skip-untranslated-strings"}, descriptionKey = "params.skipUntranslatedStrings", order = -2) |
| 37 | + protected Boolean skipTranslatedOnly; |
| 38 | + |
| 39 | + @CommandLine.Option(names = {"--skip-untranslated-files"}, descriptionKey = "params.skipUntranslatedFiles", order = -2) |
| 40 | + protected Boolean skipUntranslatedFiles; |
| 41 | + |
| 42 | + @CommandLine.Option(names = {"--export-only-approved"}, descriptionKey = "params.exportOnlyApproved", order = -2) |
| 43 | + protected Boolean exportApprovedOnly; |
| 44 | + |
| 45 | + @CommandLine.Option(names = {"--keep-archive"}, descriptionKey = "params.keepArchive", order = -2) |
| 46 | + protected boolean keepArchive; |
| 47 | + |
| 48 | + @CommandLine.Option(names = {"--all"}, descriptionKey = "crowdin.download.all", order = -2) |
| 49 | + protected boolean all; |
| 50 | + |
| 51 | + @CommandLine.Option(names = {"--dryrun"}, descriptionKey = "dryrun") |
| 52 | + protected boolean dryrun; |
| 53 | + |
| 54 | + @CommandLine.Option(names = {"--tree"}, descriptionKey = "tree.dryrun") |
| 55 | + protected boolean treeView; |
| 56 | + |
| 57 | + @CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain") |
| 58 | + protected boolean plainView; |
| 59 | + |
| 60 | + @Override |
| 61 | + protected NewAction<PropertiesWithFiles, ProjectClient> getAction(Actions actions) { |
| 62 | + return (dryrun) |
| 63 | + ? actions.listTranslations(noProgress, treeView, false, plainView, all, true, false) |
| 64 | + : actions.download(new FsFiles(), noProgress, languageIds, excludeLanguageIds, pseudo, branchName, ignoreMatch, isVerbose, plainView, all, keepArchive); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + protected boolean isAnsi() { |
| 69 | + return super.isAnsi() && !plainView; |
| 70 | + } |
| 71 | + |
| 72 | + @Override |
| 73 | + protected void updateParams(ParamsWithFiles params) { |
| 74 | + params.setExportOptions(skipTranslatedOnly, skipUntranslatedFiles, exportApprovedOnly); |
| 75 | + } |
| 76 | + |
| 77 | + @Override |
| 78 | + protected List<String> checkOptions() { |
| 79 | + List<String> errors = new ArrayList<>(); |
| 80 | + if (languageIds != null && excludeLanguageIds != null) { |
| 81 | + errors.add(RESOURCE_BUNDLE.getString("error.download.include_exclude_lang_conflict")); |
| 82 | + } |
| 83 | + return errors; |
| 84 | + } |
| 85 | +} |
0 commit comments