-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bb43466
commit 626301b
Showing
16 changed files
with
286 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/crowdin/cli/commands/actions/ProjectAddAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
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.commands.functionality.PropertiesBeanUtils; | ||
import com.crowdin.cli.commands.functionality.RequestBuilder; | ||
import com.crowdin.cli.properties.ProjectProperties; | ||
import com.crowdin.cli.utils.console.ExecutionStatus; | ||
import com.crowdin.client.projectsgroups.model.AddProjectRequest; | ||
import com.crowdin.client.projectsgroups.model.Project; | ||
import com.crowdin.client.projectsgroups.model.Visibility; | ||
import lombok.AllArgsConstructor; | ||
|
||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
import static com.crowdin.cli.BaseCli.RESOURCE_BUNDLE; | ||
|
||
@AllArgsConstructor | ||
class ProjectAddAction implements NewAction<ProjectProperties, ProjectClient> { | ||
|
||
private final String name; | ||
private final boolean isStringBased; | ||
private final String sourceLanguage; | ||
private final List<String> languages; | ||
private final boolean isPublic; | ||
private final boolean plainView; | ||
|
||
@Override | ||
public void act(Outputter out, ProjectProperties properties, ProjectClient client) { | ||
boolean isOrganization = PropertiesBeanUtils.isOrganization(properties.getBaseUrl()); | ||
String sourceLang = Objects.nonNull(sourceLanguage) ? sourceLanguage : "en"; | ||
Visibility visibility = isOrganization ? null : isPublic ? Visibility.OPEN : Visibility.PRIVATE; | ||
|
||
AddProjectRequest request = RequestBuilder.addProject(name, isStringBased, sourceLang, languages, visibility, isOrganization); | ||
Project project = client.addProject(request); | ||
if (!plainView) { | ||
out.println(ExecutionStatus.OK.withIcon( | ||
String.format(RESOURCE_BUNDLE.getString("message.project.list"), project.getId(), project.getName()) | ||
)); | ||
} else { | ||
out.println(project.getId().toString()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/com/crowdin/cli/commands/picocli/ProjectAddSubcommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
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.Command; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Parameters; | ||
|
||
import java.util.List; | ||
|
||
@Command( | ||
name = CommandNames.ADD, | ||
sortOptions = false | ||
) | ||
class ProjectAddSubcommand extends ActCommandProject { | ||
|
||
@Parameters(descriptionKey = "crowdin.project.add.name") | ||
protected String name; | ||
|
||
@Option(names = {"-l", "--language"}, required = true, paramLabel = "...", order = -2, descriptionKey = "crowdin.project.add.language") | ||
protected List<String> languages; | ||
|
||
@Option(names = {"--source-language"}, paramLabel = "...", order = -2, descriptionKey = "crowdin.project.add.source-language") | ||
protected String sourceLanguage; | ||
|
||
@Option(names = {"--public"}, order = -2, descriptionKey = "crowdin.project.add.public") | ||
protected boolean isPublic = false; | ||
|
||
@Option(names = {"--string-based"}, order = -2, descriptionKey = "crowdin.project.add.string-based") | ||
protected boolean isStringBased = false; | ||
|
||
@Option(names = {"--plain"}, descriptionKey = "crowdin.list.usage.plain") | ||
protected boolean plainView; | ||
|
||
@Override | ||
protected NewAction<ProjectProperties, ProjectClient> getAction(Actions actions) { | ||
return actions.projectAdd(this.name, this.isStringBased, this.sourceLanguage, this.languages, this.isPublic, this.plainView); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/test/java/com/crowdin/cli/commands/actions/ProjectAddActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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.client.projectsgroups.model.*; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.List; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
class ProjectAddActionTest { | ||
|
||
private ProjectClient client = mock(ProjectClient.class); | ||
private NewAction<ProjectProperties, ProjectClient> action; | ||
private ProjectProperties properties = new ProjectProperties(); | ||
private static final String PROJECT_TITLE = "project"; | ||
private static final List<String> TARGET_LANGUAGE = List.of("uk"); | ||
|
||
@Test | ||
public void testProjectAdd_FileBased() { | ||
properties.setBaseUrl("https://api.crowdin.com"); | ||
Project project = new Project(); | ||
project.setName(PROJECT_TITLE); | ||
project.setId(1L); | ||
|
||
FilesBasedProjectRequest request = new FilesBasedProjectRequest(); | ||
request.setName(PROJECT_TITLE); | ||
request.setTargetLanguageIds(TARGET_LANGUAGE); | ||
request.setSourceLanguageId("en"); | ||
request.setVisibility("PRIVATE"); | ||
|
||
when(client.addProject(request)).thenReturn(project); | ||
|
||
action = new ProjectAddAction(PROJECT_TITLE, false, null, TARGET_LANGUAGE, false, false); | ||
action.act(Outputter.getDefault(), properties, client); | ||
|
||
verify(client).addProject(request); | ||
verifyNoMoreInteractions(client); | ||
} | ||
|
||
@Test | ||
public void testProjectAdd_StringBased() { | ||
properties.setBaseUrl("https://api.crowdin.com"); | ||
Project project = new Project(); | ||
project.setName(PROJECT_TITLE); | ||
project.setId(1L); | ||
|
||
StringsBasedProjectRequest request = new StringsBasedProjectRequest(); | ||
request.setName(PROJECT_TITLE); | ||
request.setType(Type.STRINGS_BASED); | ||
request.setTargetLanguageIds(TARGET_LANGUAGE); | ||
request.setSourceLanguageId("fr"); | ||
request.setVisibility("OPEN"); | ||
|
||
when(client.addProject(request)).thenReturn(project); | ||
|
||
action = new ProjectAddAction(PROJECT_TITLE, true, "fr", TARGET_LANGUAGE, true, false); | ||
action.act(Outputter.getDefault(), properties, client); | ||
|
||
verify(client).addProject(request); | ||
verifyNoMoreInteractions(client); | ||
} | ||
|
||
@Test | ||
public void testProjectAdd_Enterprise() { | ||
properties.setBaseUrl("https://companyname.crowdin.com"); | ||
Project project = new Project(); | ||
project.setName(PROJECT_TITLE); | ||
project.setId(1L); | ||
|
||
FilesBasedProjectRequest request = new FilesBasedProjectRequest(); | ||
request.setName(PROJECT_TITLE); | ||
request.setTargetLanguageIds(TARGET_LANGUAGE); | ||
request.setSourceLanguageId("fr"); | ||
|
||
when(client.addProject(request)).thenReturn(project); | ||
|
||
action = new ProjectAddAction(PROJECT_TITLE, false, "fr", TARGET_LANGUAGE, true, true); | ||
action.act(Outputter.getDefault(), properties, client); | ||
|
||
verify(client).addProject(request); | ||
verifyNoMoreInteractions(client); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/test/java/com/crowdin/cli/commands/picocli/ProjectAddSubcommandTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.crowdin.cli.commands.picocli; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.Mockito.verify; | ||
|
||
class ProjectAddSubcommandTest extends PicocliTestUtils { | ||
|
||
@Test | ||
public void testProjectAddInvalidOptions() { | ||
this.executeInvalidParams(CommandNames.PROJECT, CommandNames.ADD); | ||
} | ||
|
||
@Test | ||
public void testProjectAdd() { | ||
this.execute(CommandNames.PROJECT, CommandNames.ADD, "name", "--language", "uk"); | ||
verify(actionsMock).projectAdd(any(), anyBoolean(), any(), any(), anyBoolean(), anyBoolean()); | ||
this.check(true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
:includedir: ../generated-picocli-docs | ||
:command: crowdin-project-add | ||
|
||
== crowdin project add | ||
|
||
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] |
Oops, something went wrong.