Skip to content

Commit

Permalink
fix: suppress progress output for crowdin file download with --no-pro…
Browse files Browse the repository at this point in the history
…gress (#880)
  • Loading branch information
by-su authored Jan 15, 2025
1 parent 595ccb4 commit 139bc9b
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/crowdin/cli/commands/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ NewAction<PropertiesWithFiles, ProjectClient> preTranslate(

NewAction<ProjectProperties, ProjectClient> fileUploadTranslation(File file, String branch, String dest, String languageId, boolean plainView);

NewAction<ProjectProperties, ProjectClient> fileDownload(String file, String branch, String destParam);
NewAction<ProjectProperties, ProjectClient> fileDownload(String file, String branch, boolean noProgress, String destParam);

NewAction<ProjectProperties, ProjectClient> fileDownloadTranslation(String file, String languageId, String branch, String destParam);
NewAction<ProjectProperties, ProjectClient> fileDownloadTranslation(String file, String languageId, String branch, boolean noProgress, String destParam);

NewAction<ProjectProperties, ProjectClient> fileDelete(String file, String branch);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,13 @@ public NewAction<ProjectProperties, ProjectClient> fileUploadTranslation(File fi
}

@Override
public NewAction<ProjectProperties, ProjectClient> fileDownload(String file, String branch, String destParam) {
return new FileDownloadAction(file, branch, destParam);
public NewAction<ProjectProperties, ProjectClient> fileDownload(String file, String branch, boolean noProgress, String destParam) {
return new FileDownloadAction(file, branch, noProgress, destParam);
}

@Override
public NewAction<ProjectProperties, ProjectClient> fileDownloadTranslation(String file, String languageId, String branch, String destParam) {
return new FileDownloadTranslationAction(file, languageId, branch, destParam);
public NewAction<ProjectProperties, ProjectClient> fileDownloadTranslation(String file, String languageId, String branch, boolean noProgress, String destParam) {
return new FileDownloadTranslationAction(file, languageId, branch, noProgress, destParam);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ class FileDownloadAction implements NewAction<ProjectProperties, ProjectClient>

private final String file;
private final String branch;
private final boolean noProgress;
private final String dest;

public FileDownloadAction(String file, String branch, String dest) {
this.file = file;
this.branch = branch;
this.noProgress = false;
this.dest = dest;
}

@Override
public void act(Outputter out, ProjectProperties properties, ProjectClient client) {
CrowdinProjectFull project = ConsoleSpinner
.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info",
false, false, () -> client.downloadFullProject(branch));
noProgress, false, () -> client.downloadFullProject(branch));
boolean isStringsBasedProject = Objects.equals(project.getType(), Type.STRINGS_BASED);
if (isStringsBasedProject) {
out.println(WARNING.withIcon(RESOURCE_BUNDLE.getString("message.no_file_string_project")));
Expand All @@ -56,7 +64,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
out,
"message.spinner.downloading_file",
"error.downloading_file",
false,
noProgress,
false,
() -> {
URL url = client.downloadFile(foundFile.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ public class FileDownloadTranslationAction implements NewAction<ProjectPropertie
private final String file;
private final String languageId;
private final String branch;
private final boolean noProgress;
private final String dest;

@Override
public void act(Outputter out, ProjectProperties properties, ProjectClient client) {
CrowdinProjectFull project = ConsoleSpinner
.execute(out, "message.spinner.fetching_project_info", "error.collect_project_info",
false, false, client::downloadFullProject);
noProgress, false, client::downloadFullProject);
boolean isStringsBasedProject = Objects.equals(project.getType(), Type.STRINGS_BASED);
if (isStringsBasedProject) {
out.println(WARNING.withIcon(RESOURCE_BUNDLE.getString("message.no_file_string_project")));
Expand Down Expand Up @@ -82,7 +83,7 @@ public void act(Outputter out, ProjectProperties properties, ProjectClient clien
out,
"message.spinner.building_translation",
"error.building_translation",
false,
noProgress,
false,
() -> client.buildProjectFileTranslation(sourceFileInfo.getId(), request)
);
Expand All @@ -99,7 +100,7 @@ private void saveToFile(String destPath, URL url, Outputter out) {
out,
"message.spinner.downloading_translation",
"error.write_file",
false,
noProgress,
false,
() -> {
FilesInterface files = new FsFiles();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class FileDownloadSubcommand extends ActCommandProject {
@Override
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
if (Objects.nonNull(languageId))
return actions.fileDownloadTranslation(file, languageId, branch, destination);
return actions.fileDownload(file, branch, destination);
return actions.fileDownloadTranslation(file, languageId, branch, noProgress, destination);
return actions.fileDownload(file, branch, noProgress, destination);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ void testFileUploadTranslation() {

@Test
void testFileDownload() {
assertNotNull(actions.fileDownload(null, null, null));
assertNotNull(actions.fileDownload(null, null, false, null));
}

@Test
void testFileDownloadTranslation() {
assertNotNull(actions.fileDownloadTranslation(null, null,null, null));
assertNotNull(actions.fileDownloadTranslation(null, null,null, false, null));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testDownload() {
when(client.downloadFile(eq(101L)))
.thenReturn(urlMock);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadAction("first.po", null, "dest");
NewAction<ProjectProperties, ProjectClient> action = new FileDownloadAction("first.po", null, false, "dest");
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject(any());
Expand All @@ -75,7 +75,7 @@ public void testDownload_StringBasedProject() {
when(client.downloadFullProject(any()))
.thenReturn(build);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadAction("first.po", "main", "dest");
NewAction<ProjectProperties, ProjectClient> action = new FileDownloadAction("first.po", "main", false, "dest");
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject(any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testDownloadTranslation() {
when(client.buildProjectFileTranslation(eq(101L), eq(request)))
.thenReturn(urlMock);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, null);
NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, false, null);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -86,7 +86,7 @@ public void testDownloadTranslationWithDest() {
when(client.buildProjectFileTranslation(eq(101L), eq(request)))
.thenReturn(urlMock);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, "path/to/save");
NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, false, "path/to/save");
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand All @@ -108,7 +108,7 @@ public void testDownloadTranslation_StringBasedProject() {
when(client.downloadFullProject())
.thenReturn(build);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, "path/to/save");
NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "ua", null, false, "path/to/save");
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down Expand Up @@ -137,7 +137,7 @@ public void testDownloadTranslation_AllLanguages() {
when(client.buildProjectFileTranslation(eq(101L), any()))
.thenReturn(urlMock);

NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "all", null, null);
NewAction<ProjectProperties, ProjectClient> action = new FileDownloadTranslationAction("first.po", "all", null, false, null);
action.act(Outputter.getDefault(), pb, client);

verify(client).downloadFullProject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class FileDownloadSubcommandTest extends PicocliTestUtils {
@Test
public void testFileDownload() {
this.execute(CommandNames.FILE, CommandNames.FILE_DOWNLOAD, "file.txt");
verify(actionsMock).fileDownload(any(), any(), any());
verify(actionsMock).fileDownload(any(), any(), false, any());
this.check(true);
}

@Test
public void testFileDownloadTranslations() {
this.execute(CommandNames.FILE, CommandNames.FILE_DOWNLOAD, "file.txt", "--language", "uk");
verify(actionsMock).fileDownloadTranslation(any(), any(), any(), any());
verify(actionsMock).fileDownloadTranslation(any(), any(), any(), false, any());
this.check(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ void mockActions() {
.thenReturn(actionMock);
when(actionsMock.fileUploadTranslation(any(), any(), any(), any(), anyBoolean()))
.thenReturn(actionMock);
when(actionsMock.fileDownload(any(), any(), any()))
when(actionsMock.fileDownload(any(), any(), anyBoolean(), any()))
.thenReturn(actionMock);
when(actionsMock.fileDownloadTranslation(any(), any(), any(), any()))
when(actionsMock.fileDownloadTranslation(any(), any(), any(), anyBoolean(), any()))
.thenReturn(actionMock);
when(actionsMock.fileDelete(any(), any()))
.thenReturn(actionMock);
Expand Down

0 comments on commit 139bc9b

Please sign in to comment.