Skip to content

Commit

Permalink
app uninstall
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ committed Nov 13, 2024
1 parent 700ee5f commit 8a8d553
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/com/crowdin/cli/client/CrowdinClientCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ protected static <T> T executeRequest(Supplier<T> r) {
return executeRequest(new HashMap<BiPredicate<String, String>, RuntimeException>(), r);
}

protected static void executeRequest(Runnable r) {
executeRequest(() -> {
r.run();
return null;
});
}

protected static <T, R extends Exception> T executeRequest(Map<BiPredicate<String, String>, R> errorHandlers, Supplier<T> r) throws R {
try {
return r.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -538,4 +538,9 @@ public List<ApplicationInstallation> listApplications() {
this.client.getApplicationsApi().listApplicationInstallations(limit, offset)
);
}

@Override
public void uninstallApplication(String id, boolean force) {
executeRequest(() -> this.client.getApplicationsApi().deleteApplicationInstallation(id, force));
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/crowdin/cli/client/ProjectClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,6 @@ default CrowdinProjectFull downloadFullProject() {
Project addProject(AddProjectRequest request);

List<ApplicationInstallation> listApplications();

void uninstallApplication(String id, boolean force);
}
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 @@ -151,4 +151,6 @@ NewAction<PropertiesWithFiles, ProjectClient> preTranslate(
NewAction<ProjectProperties, ProjectClient> projectAdd(String name, boolean isStringBased, String sourceLanguage, List<String> languages, boolean isPublic, boolean plainView);

NewAction<ProjectProperties, ProjectClient> listApps(boolean plainView);

NewAction<ProjectProperties, ProjectClient> uninstallApp(String id, Boolean force);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.crowdin.cli.commands.actions;

import com.crowdin.cli.client.ProjectClient;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.commands.Outputter;
import com.crowdin.cli.properties.ProjectProperties;
import com.crowdin.cli.utils.console.ExecutionStatus;
import lombok.RequiredArgsConstructor;

import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE;

@RequiredArgsConstructor
class AppUninstallAction implements NewAction<ProjectProperties, ProjectClient> {

private final String id;
private final boolean force;

@Override
public void act(Outputter out, ProjectProperties pb, ProjectClient client) {
client.uninstallApplication(id, force);
out.println(ExecutionStatus.OK.withIcon(String.format(RESOURCE_BUNDLE.getString("message.application.uninstall"), id)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,9 @@ public NewAction<ProjectProperties, ProjectClient> projectAdd(String name, boole
public NewAction<ProjectProperties, ProjectClient> listApps(boolean plainView) {
return new AppListAction(plainView);
}

@Override
public NewAction<ProjectProperties, ProjectClient> uninstallApp(String id, Boolean force) {
return new AppUninstallAction(id, force);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.crowdin.cli.commands.picocli;

import com.crowdin.cli.client.ProjectClient;
import com.crowdin.cli.commands.Actions;
import com.crowdin.cli.commands.NewAction;
import com.crowdin.cli.properties.ProjectProperties;
import picocli.CommandLine;

@CommandLine.Command(
sortOptions = false,
name = CommandNames.UNINSTALL
)
class AppUninstallSubcommand extends ActCommandProject {

@CommandLine.Parameters(descriptionKey = "crowdin.app.uninstall.identifier")
protected String identifier;

@CommandLine.Option(names = {"--force"}, descriptionKey = "crowdin.app.uninstall.force", order = -2)
protected boolean force;

@Override
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) {
return actions.uninstallApp(identifier, force);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
name = CommandNames.APP,
subcommands = {
AppListSubcommand.class,
AppUninstallSubcommand.class,
}
)
class ApplicationSubcommand extends HelpCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,5 @@ public final class CommandNames {
public static final String PROJECT = "project";
public static final String BROWSE = "browse";
public static final String APP = "app";
public static final String UNINSTALL = "uninstall";
}
7 changes: 7 additions & 0 deletions src/main/resources/messages/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,12 @@ crowdin.app.usage.customSynopsis=@|fg(green) crowdin app|@ [SUBCOMMAND] [CONFIG
crowdin.app.list.usage.description=List apps
crowdin.app.list.usage.customSynopsis=@|fg(green) crowdin app list|@ [CONFIG OPTIONS] [OPTIONS]

# CROWDIN BRANCH DELETE COMMAND
crowdin.app.uninstall.usage.description=Uninstall the application
crowdin.app.uninstall.usage.customSynopsis=@|fg(green) crowdin app uninstall|@ <identifier> [CONFIG OPTIONS] [OPTIONS]
crowdin.app.uninstall.identifier=Application identifier
crowdin.app.uninstall.force=Force to delete application installation

error.collect_project_info=Failed to collect project info. Please contact our support team for help
error.no_sources=No sources found for '%s' pattern. Check the source paths in your configuration file
error.only_enterprise=Operation is available only for Crowdin Enterprise
Expand Down Expand Up @@ -780,6 +786,7 @@ message.label.already_exists=Label '%s' already exists in the project
message.label.deleted=@|green Label '%s' deleted successfully|@

message.application.list=@|yellow %s|@ @|green %s|@
message.application.uninstall=@|green Application %s was uninstalled|@

message.delete_obsolete.obsolete_file_delete='%s' file was deleted
message.delete_obsolete.obsolete_directory_delete=No obsolete files were found
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.crowdin.cli.commands.picocli;

import org.junit.jupiter.api.Test;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.verify;

public class AppUninstallSubcommandTest extends PicocliTestUtils {

@Test
public void testAppUninstall() {
var appId = "test-app";
this.execute(CommandNames.APP, CommandNames.UNINSTALL, appId);
verify(actionsMock).uninstallApp(appId, false);
this.check(true);
}

@Test
public void testAppUninstallForce() {
var appId = "test-app";
this.execute(CommandNames.APP, CommandNames.UNINSTALL, appId, "--force");
verify(actionsMock).uninstallApp(appId, true);
this.check(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void mockActions() {
when(actionsMock.branchEdit(any(), any(), any(), any(), anyBoolean(), anyBoolean()))
.thenReturn(actionMock);
when(actionsMock.listApps(anyBoolean())).thenReturn(actionMock);
when(actionsMock.uninstallApp(anyString(), anyBoolean())).thenReturn(actionMock);
}

private void mockBuilders() {
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.3
version.com.github.crowdin..crowdin-api-client-java=1.19.4

plugin.org.asciidoctor.jvm.convert=3.3.2

Expand Down
16 changes: 16 additions & 0 deletions website/mantemplates/crowdin-app-uninstall.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
:includedir: ../generated-picocli-docs
:command: crowdin-app-uninstall

== crowdin app uninstall

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]
1 change: 1 addition & 0 deletions website/sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const sidebars = {
collapsed: true,
items: [
'commands/crowdin-app-list',
'commands/crowdin-app-uninstall',
]
}
],
Expand Down

0 comments on commit 8a8d553

Please sign in to comment.