From d5af295d6508f9b6a61ce0824bb4fb5bac690c40 Mon Sep 17 00:00:00 2001 From: Kateryna Oblakevych Date: Mon, 25 Nov 2024 00:55:01 -0700 Subject: [PATCH] feat: bundle browse command (#866) --- .../com/crowdin/cli/client/ClientBundle.java | 1 + .../cli/client/CrowdinClientBundle.java | 5 ++++ .../com/crowdin/cli/commands/Actions.java | 2 ++ .../commands/actions/BundleBrowseAction.java | 25 +++++++++++++++++++ .../cli/commands/actions/CliActions.java | 5 ++++ .../commands/picocli/ActCommandBundle.java | 1 + .../picocli/BundleBrowseSubcommand.java | 24 ++++++++++++++++++ .../commands/picocli/BundleSubcommand.java | 1 + .../resources/messages/messages.properties | 5 ++++ .../cli/commands/actions/CliActionsTest.java | 5 ++++ .../picocli/BundleBrowseSubcommandTest.java | 21 ++++++++++++++++ .../commands/picocli/PicocliTestUtils.java | 2 ++ versions.properties | 2 +- .../mantemplates/crowdin-bundle-browse.adoc | 21 ++++++++++++++++ website/sidebars.js | 1 + 15 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/crowdin/cli/commands/actions/BundleBrowseAction.java create mode 100644 src/main/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommand.java create mode 100644 src/test/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommandTest.java create mode 100644 website/mantemplates/crowdin-bundle-browse.adoc diff --git a/src/main/java/com/crowdin/cli/client/ClientBundle.java b/src/main/java/com/crowdin/cli/client/ClientBundle.java index 6d0bfced3..d278013e3 100644 --- a/src/main/java/com/crowdin/cli/client/ClientBundle.java +++ b/src/main/java/com/crowdin/cli/client/ClientBundle.java @@ -21,4 +21,5 @@ public interface ClientBundle extends Client { BundleExport checkExportingBundle(Long tmId, String exportId); + String getBundleUrl(Long bundleId); } diff --git a/src/main/java/com/crowdin/cli/client/CrowdinClientBundle.java b/src/main/java/com/crowdin/cli/client/CrowdinClientBundle.java index 41ee841c9..1e61ba6fe 100644 --- a/src/main/java/com/crowdin/cli/client/CrowdinClientBundle.java +++ b/src/main/java/com/crowdin/cli/client/CrowdinClientBundle.java @@ -59,4 +59,9 @@ public BundleExport checkExportingBundle(Long id, String exportId) { .getData()); } + @Override + public String getBundleUrl(Long bundleId) { + return this.getBundle(bundleId).getWebUrl(); + } + } \ No newline at end of file diff --git a/src/main/java/com/crowdin/cli/commands/Actions.java b/src/main/java/com/crowdin/cli/commands/Actions.java index fe78ac24f..506777a44 100644 --- a/src/main/java/com/crowdin/cli/commands/Actions.java +++ b/src/main/java/com/crowdin/cli/commands/Actions.java @@ -106,6 +106,8 @@ NewAction taskAdd( NewAction bundleAdd(String name, String format, List source, List ignore, String translation, List labels, boolean plainView, boolean includeProjectSourceLanguage, boolean isMultilingual); + NewAction bundleBrowse(Long id); + NewAction checkNewVersion(); NewAction preTranslate( diff --git a/src/main/java/com/crowdin/cli/commands/actions/BundleBrowseAction.java b/src/main/java/com/crowdin/cli/commands/actions/BundleBrowseAction.java new file mode 100644 index 000000000..9efa119a5 --- /dev/null +++ b/src/main/java/com/crowdin/cli/commands/actions/BundleBrowseAction.java @@ -0,0 +1,25 @@ +package com.crowdin.cli.commands.actions; + +import com.crowdin.cli.client.ClientBundle; +import com.crowdin.cli.commands.NewAction; +import com.crowdin.cli.commands.Outputter; +import com.crowdin.cli.properties.ProjectProperties; +import lombok.AllArgsConstructor; + +import java.awt.*; +import java.net.URI; + +@AllArgsConstructor +class BundleBrowseAction implements NewAction { + + Long id; + + @Override + public void act(Outputter out, ProjectProperties pb, ClientBundle client) { + try { + Desktop.getDesktop().browse(new URI(client.getBundleUrl(id))); + } catch (Exception e) { + throw new RuntimeException("Unexpected error"); + } + } +} diff --git a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java index fff90eb0e..3e7a3c043 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java +++ b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java @@ -215,6 +215,11 @@ public NewAction bundleAdd(String name, String return new BundleAddAction(name, format, source, ignore, translation, labels, plainView, includeProjectSourceLanguage, isMultilingual); } + @Override + public NewAction bundleBrowse(Long id) { + return new BundleBrowseAction(id); + } + @Override public NewAction checkNewVersion() { return new CheckNewVersionAction(); diff --git a/src/main/java/com/crowdin/cli/commands/picocli/ActCommandBundle.java b/src/main/java/com/crowdin/cli/commands/picocli/ActCommandBundle.java index 3ea4aa247..262c0841e 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/ActCommandBundle.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/ActCommandBundle.java @@ -2,6 +2,7 @@ import com.crowdin.cli.client.ClientBundle; import com.crowdin.cli.client.Clients; +import com.crowdin.cli.client.ProjectClient; import com.crowdin.cli.commands.Outputter; import com.crowdin.cli.properties.ProjectParams; import com.crowdin.cli.properties.ProjectProperties; diff --git a/src/main/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommand.java new file mode 100644 index 000000000..0ae19d849 --- /dev/null +++ b/src/main/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommand.java @@ -0,0 +1,24 @@ +package com.crowdin.cli.commands.picocli; + +import com.crowdin.cli.client.ClientBundle; +import com.crowdin.cli.client.ProjectClient; +import com.crowdin.cli.commands.Actions; +import com.crowdin.cli.commands.NewAction; +import com.crowdin.cli.commands.Outputter; +import com.crowdin.cli.properties.ProjectProperties; +import picocli.CommandLine; + +@CommandLine.Command( + name = CommandNames.BROWSE, + sortOptions = false +) +class BundleBrowseSubcommand extends ActCommandBundle { + + @CommandLine.Parameters(descriptionKey = "crowdin.bundle.browse.id") + protected Long id; + + @Override + protected NewAction getAction(Actions actions) { + return actions.bundleBrowse(id); + } +} diff --git a/src/main/java/com/crowdin/cli/commands/picocli/BundleSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/BundleSubcommand.java index dc62ea464..7142ff09d 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/BundleSubcommand.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/BundleSubcommand.java @@ -8,6 +8,7 @@ BundleListSubcommand.class, BundleAddSubcommand.class, BundleDownloadSubcommand.class, + BundleBrowseSubcommand.class } ) class BundleSubcommand extends HelpCommand { diff --git a/src/main/resources/messages/messages.properties b/src/main/resources/messages/messages.properties index a1a28789c..1f4900b1a 100755 --- a/src/main/resources/messages/messages.properties +++ b/src/main/resources/messages/messages.properties @@ -351,6 +351,11 @@ crowdin.bundle.add.isMultilingual=Export translations in multilingual file crowdin.bundle.download.usage.description=Download bundle crowdin.bundle.download.usage.customSynopsis=@|fg(green) crowdin bundle download |@ +# CROWDIN BUNDLE BROWSE COMMAND +crowdin.bundle.browse.usage.description=Open bundle in the web browser +crowdin.bundle.browse.usage.customSynopsis=@|fg(green) crowdin bundle browse|@ [CONFIG OPTIONS] [OPTIONS] +crowdin.bundle.browse.id=Bundle id + # CROWDIN COMMENT COMMAND crowdin.comment.usage.description=Manage string comments and issues crowdin.comment.usage.customSynopsis=@|fg(green) crowdin comment|@ [SUBCOMMAND] [CONFIG OPTIONS] [OPTIONS] diff --git a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java index 9ffb8cbec..b0eff0922 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java @@ -196,4 +196,9 @@ void testBranchClone() { void testProjectAdd() { assertNotNull(actions.projectAdd(null, false, null, null, false, false)); } + + @Test + void testBundleBrowse() { + assertNotNull(actions.bundleBrowse(null)); + } } diff --git a/src/test/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommandTest.java b/src/test/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommandTest.java new file mode 100644 index 000000000..ab531f079 --- /dev/null +++ b/src/test/java/com/crowdin/cli/commands/picocli/BundleBrowseSubcommandTest.java @@ -0,0 +1,21 @@ +package com.crowdin.cli.commands.picocli; + +import org.junit.jupiter.api.Test; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.verify; + +public class BundleBrowseSubcommandTest extends PicocliTestUtils { + + @Test + public void testBundleBrowseInvalidOptions() { + this.executeInvalidParams(CommandNames.BUNDLE, CommandNames.BROWSE); + } + + @Test + public void testProjectBrowse() { + this.execute(CommandNames.BUNDLE, CommandNames.BROWSE, "1"); + verify(actionsMock).bundleBrowse(any()); + this.check(true); + } +} diff --git a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java index e5a9d276e..c624d38d4 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java @@ -104,6 +104,8 @@ void mockActions() { .thenReturn(actionMock); when(actionsMock.bundleAdd(any(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())) .thenReturn(actionMock); + when(actionsMock.bundleBrowse(any())) + .thenReturn(actionMock); when(actionsMock.preTranslate(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), any(), any())) .thenReturn(actionMock); when(actionsMock.screenshotList(any(), anyBoolean())) diff --git a/versions.properties b/versions.properties index b93d55e9c..4a2ea275d 100644 --- a/versions.properties +++ b/versions.properties @@ -43,7 +43,7 @@ version.commons-io..commons-io=2.16.1 version.commons-cli..commons-cli=1.7.0 -version.com.github.crowdin..crowdin-api-client-java=1.19.4 +version.com.github.crowdin..crowdin-api-client-java=1.19.5 plugin.org.asciidoctor.jvm.convert=3.3.2 diff --git a/website/mantemplates/crowdin-bundle-browse.adoc b/website/mantemplates/crowdin-bundle-browse.adoc new file mode 100644 index 000000000..43d0adc05 --- /dev/null +++ b/website/mantemplates/crowdin-bundle-browse.adoc @@ -0,0 +1,21 @@ +:includedir: ../generated-picocli-docs +:command: crowdin-bundle-browse + +== crowdin bundle browse + +include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-description] + +include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-synopsis] + +include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-arguments] + +include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-commands] + +include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-options] + +include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-footer] + +=== See also + +* link:https://support.crowdin.com/bundles/[Target File Bundles] +* link:/crowdin-cli/commands/crowdin-bundle[`crowdin bundle` command] diff --git a/website/sidebars.js b/website/sidebars.js index e277d7235..d677782ee 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -132,6 +132,7 @@ const sidebars = { 'commands/crowdin-bundle-list', 'commands/crowdin-bundle-add', 'commands/crowdin-bundle-download', + 'commands/crowdin-bundle-browse', ] },