Skip to content

Commit d5af295

Browse files
authoredNov 25, 2024··
feat: bundle browse command (#866)
1 parent afffab0 commit d5af295

15 files changed

+120
-1
lines changed
 

‎src/main/java/com/crowdin/cli/client/ClientBundle.java

+1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ public interface ClientBundle extends Client {
2121

2222
BundleExport checkExportingBundle(Long tmId, String exportId);
2323

24+
String getBundleUrl(Long bundleId);
2425
}

‎src/main/java/com/crowdin/cli/client/CrowdinClientBundle.java

+5
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ public BundleExport checkExportingBundle(Long id, String exportId) {
5959
.getData());
6060
}
6161

62+
@Override
63+
public String getBundleUrl(Long bundleId) {
64+
return this.getBundle(bundleId).getWebUrl();
65+
}
66+
6267
}

‎src/main/java/com/crowdin/cli/commands/Actions.java

+2
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ NewAction<ProjectProperties, ClientTask> taskAdd(
106106

107107
NewAction<ProjectProperties, ClientBundle> bundleAdd(String name, String format, List<String> source, List<String> ignore, String translation, List<Long> labels, boolean plainView, boolean includeProjectSourceLanguage, boolean isMultilingual);
108108

109+
NewAction<ProjectProperties, ClientBundle> bundleBrowse(Long id);
110+
109111
NewAction<NoProperties, NoClient> checkNewVersion();
110112

111113
NewAction<PropertiesWithFiles, ProjectClient> preTranslate(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.crowdin.cli.commands.actions;
2+
3+
import com.crowdin.cli.client.ClientBundle;
4+
import com.crowdin.cli.commands.NewAction;
5+
import com.crowdin.cli.commands.Outputter;
6+
import com.crowdin.cli.properties.ProjectProperties;
7+
import lombok.AllArgsConstructor;
8+
9+
import java.awt.*;
10+
import java.net.URI;
11+
12+
@AllArgsConstructor
13+
class BundleBrowseAction implements NewAction<ProjectProperties, ClientBundle> {
14+
15+
Long id;
16+
17+
@Override
18+
public void act(Outputter out, ProjectProperties pb, ClientBundle client) {
19+
try {
20+
Desktop.getDesktop().browse(new URI(client.getBundleUrl(id)));
21+
} catch (Exception e) {
22+
throw new RuntimeException("Unexpected error");
23+
}
24+
}
25+
}

‎src/main/java/com/crowdin/cli/commands/actions/CliActions.java

+5
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,11 @@ public NewAction<ProjectProperties, ClientBundle> bundleAdd(String name, String
215215
return new BundleAddAction(name, format, source, ignore, translation, labels, plainView, includeProjectSourceLanguage, isMultilingual);
216216
}
217217

218+
@Override
219+
public NewAction<ProjectProperties, ClientBundle> bundleBrowse(Long id) {
220+
return new BundleBrowseAction(id);
221+
}
222+
218223
@Override
219224
public NewAction<NoProperties, NoClient> checkNewVersion() {
220225
return new CheckNewVersionAction();

‎src/main/java/com/crowdin/cli/commands/picocli/ActCommandBundle.java

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.crowdin.cli.client.ClientBundle;
44
import com.crowdin.cli.client.Clients;
5+
import com.crowdin.cli.client.ProjectClient;
56
import com.crowdin.cli.commands.Outputter;
67
import com.crowdin.cli.properties.ProjectParams;
78
import com.crowdin.cli.properties.ProjectProperties;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.crowdin.cli.commands.picocli;
2+
3+
import com.crowdin.cli.client.ClientBundle;
4+
import com.crowdin.cli.client.ProjectClient;
5+
import com.crowdin.cli.commands.Actions;
6+
import com.crowdin.cli.commands.NewAction;
7+
import com.crowdin.cli.commands.Outputter;
8+
import com.crowdin.cli.properties.ProjectProperties;
9+
import picocli.CommandLine;
10+
11+
@CommandLine.Command(
12+
name = CommandNames.BROWSE,
13+
sortOptions = false
14+
)
15+
class BundleBrowseSubcommand extends ActCommandBundle {
16+
17+
@CommandLine.Parameters(descriptionKey = "crowdin.bundle.browse.id")
18+
protected Long id;
19+
20+
@Override
21+
protected NewAction<ProjectProperties, ClientBundle> getAction(Actions actions) {
22+
return actions.bundleBrowse(id);
23+
}
24+
}

‎src/main/java/com/crowdin/cli/commands/picocli/BundleSubcommand.java

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
BundleListSubcommand.class,
99
BundleAddSubcommand.class,
1010
BundleDownloadSubcommand.class,
11+
BundleBrowseSubcommand.class
1112
}
1213
)
1314
class BundleSubcommand extends HelpCommand {

‎src/main/resources/messages/messages.properties

+5
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,11 @@ crowdin.bundle.add.isMultilingual=Export translations in multilingual file
351351
crowdin.bundle.download.usage.description=Download bundle
352352
crowdin.bundle.download.usage.customSynopsis=@|fg(green) crowdin bundle download <id>|@
353353

354+
# CROWDIN BUNDLE BROWSE COMMAND
355+
crowdin.bundle.browse.usage.description=Open bundle in the web browser
356+
crowdin.bundle.browse.usage.customSynopsis=@|fg(green) crowdin bundle browse|@ <id> [CONFIG OPTIONS] [OPTIONS]
357+
crowdin.bundle.browse.id=Bundle id
358+
354359
# CROWDIN COMMENT COMMAND
355360
crowdin.comment.usage.description=Manage string comments and issues
356361
crowdin.comment.usage.customSynopsis=@|fg(green) crowdin comment|@ [SUBCOMMAND] [CONFIG OPTIONS] [OPTIONS]

‎src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,9 @@ void testBranchClone() {
196196
void testProjectAdd() {
197197
assertNotNull(actions.projectAdd(null, false, null, null, false, false));
198198
}
199+
200+
@Test
201+
void testBundleBrowse() {
202+
assertNotNull(actions.bundleBrowse(null));
203+
}
199204
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.crowdin.cli.commands.picocli;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.mockito.ArgumentMatchers.any;
6+
import static org.mockito.Mockito.verify;
7+
8+
public class BundleBrowseSubcommandTest extends PicocliTestUtils {
9+
10+
@Test
11+
public void testBundleBrowseInvalidOptions() {
12+
this.executeInvalidParams(CommandNames.BUNDLE, CommandNames.BROWSE);
13+
}
14+
15+
@Test
16+
public void testProjectBrowse() {
17+
this.execute(CommandNames.BUNDLE, CommandNames.BROWSE, "1");
18+
verify(actionsMock).bundleBrowse(any());
19+
this.check(true);
20+
}
21+
}

‎src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java

+2
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ void mockActions() {
104104
.thenReturn(actionMock);
105105
when(actionsMock.bundleAdd(any(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean()))
106106
.thenReturn(actionMock);
107+
when(actionsMock.bundleBrowse(any()))
108+
.thenReturn(actionMock);
107109
when(actionsMock.preTranslate(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), any(), any()))
108110
.thenReturn(actionMock);
109111
when(actionsMock.screenshotList(any(), anyBoolean()))

‎versions.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ version.commons-io..commons-io=2.16.1
4343

4444
version.commons-cli..commons-cli=1.7.0
4545

46-
version.com.github.crowdin..crowdin-api-client-java=1.19.4
46+
version.com.github.crowdin..crowdin-api-client-java=1.19.5
4747

4848
plugin.org.asciidoctor.jvm.convert=3.3.2
4949

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
:includedir: ../generated-picocli-docs
2+
:command: crowdin-bundle-browse
3+
4+
== crowdin bundle browse
5+
6+
include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-description]
7+
8+
include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-synopsis]
9+
10+
include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-arguments]
11+
12+
include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-commands]
13+
14+
include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-options]
15+
16+
include::{includedir}/{command}.adoc[tag=picocli-generated-man-section-footer]
17+
18+
=== See also
19+
20+
* link:https://support.crowdin.com/bundles/[Target File Bundles]
21+
* link:/crowdin-cli/commands/crowdin-bundle[`crowdin bundle` command]

‎website/sidebars.js

+1
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const sidebars = {
132132
'commands/crowdin-bundle-list',
133133
'commands/crowdin-bundle-add',
134134
'commands/crowdin-bundle-download',
135+
'commands/crowdin-bundle-browse',
135136
]
136137
},
137138

0 commit comments

Comments
 (0)
Please sign in to comment.