Skip to content

Commit

Permalink
fix: renamed init command internals (#854)
Browse files Browse the repository at this point in the history
  • Loading branch information
yevheniyJ authored Oct 15, 2024
1 parent 32ea5f6 commit ab25e24
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 23 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 @@ -27,8 +27,8 @@ NewAction<PropertiesWithFiles, ProjectClient> download(
boolean ignoreMatch, boolean isVerbose, boolean plainView, boolean userServerSources, boolean keepArchive
);

NewAction<NoProperties, NoClient> generate(FilesInterface files, String token, String baseUrl, String basePath,
String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean skipGenerateDescription);
NewAction<NoProperties, NoClient> init(FilesInterface files, String token, String baseUrl, String basePath,
String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean quiet);

NewAction<ProjectProperties, ProjectClient> listBranches(boolean noProgress, boolean plainView);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ public NewAction<PropertiesWithFiles, ProjectClient> download(
}

@Override
public NewAction<NoProperties, NoClient> generate(FilesInterface files, String token, String baseUrl, String basePath,
String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean skipGenerateDescription
public NewAction<NoProperties, NoClient> init(FilesInterface files, String token, String baseUrl, String basePath,
String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean quiet
) {
return new GenerateAction(files, token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, skipGenerateDescription);
return new InitAction(files, token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, quiet);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static java.util.Objects.nonNull;

@RequiredArgsConstructor
class GenerateAction implements NewAction<NoProperties, NoClient> {
class InitAction implements NewAction<NoProperties, NoClient> {

public static final String BASE_PATH_DEFAULT = ".";
public static final String BASE_URL_DEFAULT = "https://api.crowdin.com";
Expand All @@ -52,7 +52,7 @@ class GenerateAction implements NewAction<NoProperties, NoClient> {
private final String translation;
private final Boolean preserveHierarchy;
private final Path destinationPath;
private final boolean skipGenerateDescription;
private final boolean quiet;

@Override
public void act(Outputter out, NoProperties noProperties, NoClient noClient) {
Expand All @@ -69,7 +69,7 @@ public void act(Outputter out, NoProperties noProperties, NoClient noClient) {
}

List<String> fileLines = Utils.readResource("/crowdin.yml");
if (!skipGenerateDescription) {
if (!quiet) {
this.updateWithUserInputs(out, asking, fileLines);
}
files.writeToFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
public class InitSubcommand extends GenericActCommand<NoProperties, NoClient> {

@CommandLine.Option(names = {"-d", "--destination"}, paramLabel = "...", descriptionKey = "crowdin.generate.destination", defaultValue = "crowdin.yml", order = -2)
@CommandLine.Option(names = {"-d", "--destination"}, paramLabel = "...", descriptionKey = "crowdin.init.destination", defaultValue = "crowdin.yml", order = -2)
private Path destinationPath;

@CommandLine.Option(names = {"-T", "--token"}, paramLabel = "...", descriptionKey = "params.token", order = -2)
Expand All @@ -43,10 +43,10 @@ public class InitSubcommand extends GenericActCommand<NoProperties, NoClient> {
private Boolean preserveHierarchy;

@CommandLine.Option(names = "--quiet", descriptionKey = "params.quiet", order = -2)
private boolean skipGenerateDescription;
private boolean quiet;

protected NewAction<NoProperties, NoClient> getAction(Actions actions) {
return actions.generate(new FsFiles(), token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, skipGenerateDescription);
return actions.init(new FsFiles(), token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, quiet);
}

protected NoProperties getProperties(PropertiesBuilders propertiesBuilders, Outputter out) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void testDownload() {

@Test
public void testGenerate() {
assertNotNull(actions.generate(new FsFiles(), null, null, null, null, null, null, null, null, false));
assertNotNull(actions.init(new FsFiles(), null, null, null, null, null, null, null, null, false));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.*;

public class GenerateActionTest {
public class InitActionTest {

TempProject project;

Expand All @@ -46,7 +46,7 @@ public void simpleTest() throws IOException {
InputStream responsesIS = setResponses(false, false, "apiToken", "42", ".");
System.setIn(responsesIS);

action = new GenerateAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class));

verify(files).writeToFile(anyString(), any());
Expand All @@ -57,7 +57,7 @@ public void simpleTest() throws IOException {
public void userInputTest() throws IOException {
FilesInterface files = mock(FilesInterface.class);

action = new GenerateAction(files, "token", "", ".", "42", "file.json", "translation.json", true, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, "token", "", ".", "42", "file.json", "translation.json", true, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class));

verify(files).writeToFile(anyString(), any());
Expand All @@ -68,7 +68,7 @@ public void userInputTest() throws IOException {
public void userInputAllTest() throws IOException {
FilesInterface files = mock(FilesInterface.class);

action = new GenerateAction(files, "token", "https://api.crowdin.com", ".", "42", "file.json", "translation.json", true, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, "token", "https://api.crowdin.com", ".", "42", "file.json", "translation.json", true, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class));

ArgumentCaptor<InputStream> contentCaptor = ArgumentCaptor.forClass(InputStream.class);
Expand All @@ -95,7 +95,7 @@ public void writeToFileThrowsTest() throws IOException {
InputStream responsesIS = setResponses(false, false, "apiToken", "42", ".");
System.setIn(responsesIS);

action = new GenerateAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class)));

verify(files).writeToFile(anyString(), any());
Expand All @@ -109,7 +109,7 @@ public void enterprisetest() throws IOException {
InputStream responsesIS = setResponses(false, true, "undefined", "apiToken", "42", ".");
System.setIn(responsesIS);

action = new GenerateAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class)));

verify(files).writeToFile(anyString(), any());
Expand All @@ -123,7 +123,7 @@ public void enterpriseUrlTest() throws IOException {
InputStream responsesIS = setResponses(false, true, "https://undefined.crowdin.com", "apiToken", "42", ".");
System.setIn(responsesIS);

action = new GenerateAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class)));

verify(files).writeToFile(anyString(), any());
Expand All @@ -137,7 +137,7 @@ public void enterpriseNoNametest() throws IOException {
InputStream responsesIS = setResponses(false, true, "", "apiToken", "42", ".");
System.setIn(responsesIS);

action = new GenerateAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
assertThrows(RuntimeException.class, () -> action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class)));

verify(files).writeToFile(anyString(), any());
Expand All @@ -152,7 +152,7 @@ public void fileExists() throws IOException {
InputStream responsesIS = setResponses(false, true, "https://undefined.crowdin.com", "apiToken", "42", ".");
System.setIn(responsesIS);

action = new GenerateAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action = new InitAction(files, null, null, null, null, null, null, null, Paths.get(project.getBasePath() + "/crowdin.yml"), false);
action.act(Outputter.getDefault(), new NoProperties(), mock(NoClient.class));

verifyNoMoreInteractions(files);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class InitSubcommandTest extends PicocliTestUtils {
public void testGenerate() {
this.execute(CommandNames.INIT);
verify(actionsMock)
.generate(any(), any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean());
.init(any(), any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean());
this.check(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void mockActions() {

when(actionsMock.download(any(), anyBoolean(), any(), any(), anyBoolean(), any(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean(), anyBoolean()))
.thenReturn(actionMock);
when(actionsMock.generate(any(), any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean()))
when(actionsMock.init(any(), any(), any(), any(), any(), any(), any(), any(), any(), anyBoolean()))
.thenReturn(actionMock);
when(actionsMock.listBranches(anyBoolean(), anyBoolean()))
.thenReturn(actionMock);
Expand Down

0 comments on commit ab25e24

Please sign in to comment.