Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bundle browse command #866

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/main/java/com/crowdin/cli/client/ClientBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ public interface ClientBundle extends Client {

BundleExport checkExportingBundle(Long tmId, String exportId);

String getBundleUrl(Long bundleId);
}
5 changes: 5 additions & 0 deletions src/main/java/com/crowdin/cli/client/CrowdinClientBundle.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ public BundleExport checkExportingBundle(Long id, String exportId) {
.getData());
}

@Override
public String getBundleUrl(Long bundleId) {
return this.getBundle(bundleId).getWebUrl();
}

}
2 changes: 2 additions & 0 deletions src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ NewAction<ProjectProperties, ClientTask> taskAdd(

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);

NewAction<ProjectProperties, ClientBundle> bundleBrowse(Long id);

NewAction<NoProperties, NoClient> checkNewVersion();

NewAction<PropertiesWithFiles, ProjectClient> preTranslate(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ProjectProperties, ClientBundle> {

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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ public NewAction<ProjectProperties, ClientBundle> bundleAdd(String name, String
return new BundleAddAction(name, format, source, ignore, translation, labels, plainView, includeProjectSourceLanguage, isMultilingual);
}

@Override
public NewAction<ProjectProperties, ClientBundle> bundleBrowse(Long id) {
return new BundleBrowseAction(id);
}

@Override
public NewAction<NoProperties, NoClient> checkNewVersion() {
return new CheckNewVersionAction();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ProjectProperties, ClientBundle> getAction(Actions actions) {
return actions.bundleBrowse(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
BundleListSubcommand.class,
BundleAddSubcommand.class,
BundleDownloadSubcommand.class,
BundleBrowseSubcommand.class
}
)
class BundleSubcommand extends HelpCommand {
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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 <id>|@

# 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|@ <id> [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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,9 @@ void testBranchClone() {
void testProjectAdd() {
assertNotNull(actions.projectAdd(null, false, null, null, false, false));
}

@Test
void testBundleBrowse() {
assertNotNull(actions.bundleBrowse(null));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion versions.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions website/mantemplates/crowdin-bundle-browse.adoc
Original file line number Diff line number Diff line change
@@ -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]
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const sidebars = {
'commands/crowdin-bundle-list',
'commands/crowdin-bundle-add',
'commands/crowdin-bundle-download',
'commands/crowdin-bundle-browse',
]
},

Expand Down
Loading