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: add bundle extra options #858

Merged
merged 2 commits into from
Oct 21, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
@@ -104,7 +104,7 @@ NewAction<ProjectProperties, ClientTask> taskAdd(

NewAction<ProjectProperties, ClientBundle> bundleList(boolean plainView, boolean isVerbose);

NewAction<ProjectProperties, ClientBundle> bundleAdd(String name, String format, List<String> source, List<String> ignore, String translation, List<Long> labels, boolean plainView);
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<NoProperties, NoClient> checkNewVersion();

Original file line number Diff line number Diff line change
@@ -32,6 +32,10 @@ class BundleAddAction implements NewAction<ProjectProperties, ClientBundle> {

private boolean plainView;

private boolean includeProjectSourceLanguage;

private boolean isMultilingual;

@Override
public void act(Outputter out, ProjectProperties pb, ClientBundle client) {
Bundle bundle;
@@ -41,6 +45,8 @@ public void act(Outputter out, ProjectProperties pb, ClientBundle client) {
Optional.ofNullable(source).ifPresent(addBundleRequest::setSourcePatterns);
Optional.ofNullable(ignore).ifPresent(addBundleRequest::setIgnorePatterns);
Optional.ofNullable(translation).ifPresent(addBundleRequest::setExportPattern);
addBundleRequest.setIncludeProjectSourceLanguage(includeProjectSourceLanguage);
addBundleRequest.setIsMultilingual(isMultilingual);

Optional.ofNullable(labels).ifPresent(addBundleRequest::setLabelIds);

Original file line number Diff line number Diff line change
@@ -211,8 +211,8 @@ public NewAction<ProjectProperties, ClientBundle> bundleList(boolean plainView,
}

@Override
public NewAction<ProjectProperties, ClientBundle> bundleAdd(String name, String format, List<String> source, List<String> ignore, String translation, List<Long> labels, boolean plainView) {
return new BundleAddAction(name, format, source, ignore, translation, labels, plainView);
public 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) {
return new BundleAddAction(name, format, source, ignore, translation, labels, plainView, includeProjectSourceLanguage, isMultilingual);
}

@Override
Original file line number Diff line number Diff line change
@@ -36,14 +36,20 @@ class BundleAddSubcommand extends ActCommandBundle {
@CommandLine.Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain")
protected boolean plainView;

@CommandLine.Option(names = {"--include-source-language"}, paramLabel = "...", descriptionKey = "crowdin.bundle.add.includeProjectSourceLanguage", order = -2)
protected boolean includeProjectSourceLanguage;

@CommandLine.Option(names = {"--multilingual"}, paramLabel = "...", descriptionKey = "crowdin.bundle.add.isMultilingual", order = -2)
protected boolean isMultilingual;

@Override
protected final boolean isAnsi() {
return super.isAnsi() && !plainView;
}

@Override
protected NewAction<ProjectProperties, ClientBundle> getAction(Actions actions) {
return actions.bundleAdd(name, format, source, ignore, translation, labels, plainView);
return actions.bundleAdd(name, format, source, ignore, translation, labels, plainView, includeProjectSourceLanguage, isMultilingual);
}

@Override
2 changes: 2 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
@@ -341,6 +341,8 @@ crowdin.bundle.add.source=Source pattern. Could be specified multiple times
crowdin.bundle.add.ignore=Ignore pattern. Could be specified multiple times
crowdin.bundle.add.translation=Bundle export pattern. Defines bundle name in resulting translations bundle
crowdin.bundle.add.label=Label identifier. Could be specified multiple times
crowdin.bundle.add.includeProjectSourceLanguage=Add project source language to bundle
crowdin.bundle.add.isMultilingual=Export translations in multilingual file

# CROWDIN BUNDLE DOWNLOAD COMMAND
crowdin.bundle.download.usage.description=Download bundle
Original file line number Diff line number Diff line change
@@ -44,6 +44,8 @@ public void testBundleAdd(String name, String format, List<String> source, List<
request.setLabelIds(labels);
request.setIgnorePatterns(ignore);
request.setSourcePatterns(source);
request.setIncludeProjectSourceLanguage(false);
request.setIsMultilingual(false);

ClientBundle client = mock(ClientBundle.class);
when(client.addBundle(request))
@@ -55,7 +57,7 @@ public void testBundleAdd(String name, String format, List<String> source, List<
setIgnorePatterns(request.getIgnorePatterns());
setSourcePatterns(request.getSourcePatterns());
}});
action = new BundleAddAction(name, format, source, ignore, translation, labels, false);
action = new BundleAddAction(name, format, source, ignore, translation, labels, false, false, false);
action.act(Outputter.getDefault(), pb, client);
verify(client).addBundle(request);
verifyNoMoreInteractions(client);
@@ -82,11 +84,13 @@ public void testAddBundleThrows() {
request.setLabelIds(null);
request.setIgnorePatterns(null);
request.setSourcePatterns(null);
request.setIsMultilingual(false);
request.setIncludeProjectSourceLanguage(false);

when(client.addBundle(request))
.thenThrow(new RuntimeException("Whoops"));

action = new BundleAddAction("", "", null, null, null, null, false);
action = new BundleAddAction("", "", null, null, null, null, false, false, false);
assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), pb, client));

verify(client).addBundle(request);
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ void mockActions() {
.thenReturn(actionMock);
when(actionsMock.bundleList(anyBoolean(), anyBoolean()))
.thenReturn(actionMock);
when(actionsMock.bundleAdd(any(), any(), any(), any(), any(), any(), anyBoolean()))
when(actionsMock.bundleAdd(any(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean()))
.thenReturn(actionMock);
when(actionsMock.preTranslate(any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean(), anyBoolean(), any(), any()))
.thenReturn(actionMock);