Skip to content

Commit

Permalink
feat: add bundle extra options (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ authored Oct 21, 2024
1 parent ca5460f commit 102c73a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 7 deletions.
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
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 102c73a

Please sign in to comment.