From f918da9d1d07a946f54f1ecac3524a5a9f854fb5 Mon Sep 17 00:00:00 2001 From: Yevheniy Oliynyk Date: Mon, 14 Oct 2024 19:15:48 +0200 Subject: [PATCH 1/2] fix: renamed init command internals --- .../java/com/crowdin/cli/commands/Actions.java | 4 ++-- .../cli/commands/actions/CliActions.java | 6 +++--- .../{GenerateAction.java => InitAction.java} | 6 +++--- .../cli/commands/picocli/InitSubcommand.java | 6 +++--- .../cli/commands/actions/CliActionsTest.java | 2 +- ...rateActionTest.java => InitActionTest.java} | 18 +++++++++--------- .../commands/picocli/InitSubcommandTest.java | 2 +- .../cli/commands/picocli/PicocliTestUtils.java | 2 +- 8 files changed, 23 insertions(+), 23 deletions(-) rename src/main/java/com/crowdin/cli/commands/actions/{GenerateAction.java => InitAction.java} (98%) rename src/test/java/com/crowdin/cli/commands/actions/{GenerateActionTest.java => InitActionTest.java} (84%) diff --git a/src/main/java/com/crowdin/cli/commands/Actions.java b/src/main/java/com/crowdin/cli/commands/Actions.java index 03448388..a0fc3a96 100644 --- a/src/main/java/com/crowdin/cli/commands/Actions.java +++ b/src/main/java/com/crowdin/cli/commands/Actions.java @@ -27,8 +27,8 @@ NewAction download( boolean ignoreMatch, boolean isVerbose, boolean plainView, boolean userServerSources, boolean keepArchive ); - NewAction generate(FilesInterface files, String token, String baseUrl, String basePath, - String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean skipGenerateDescription); + NewAction init(FilesInterface files, String token, String baseUrl, String basePath, + String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean quite); NewAction listBranches(boolean noProgress, boolean plainView); diff --git a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java index b9abf9b6..ab24399a 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java +++ b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java @@ -33,10 +33,10 @@ public NewAction download( } @Override - public NewAction generate(FilesInterface files, String token, String baseUrl, String basePath, - String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean skipGenerateDescription + public NewAction init(FilesInterface files, String token, String baseUrl, String basePath, + String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean init ) { - 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, init); } @Override diff --git a/src/main/java/com/crowdin/cli/commands/actions/GenerateAction.java b/src/main/java/com/crowdin/cli/commands/actions/InitAction.java similarity index 98% rename from src/main/java/com/crowdin/cli/commands/actions/GenerateAction.java rename to src/main/java/com/crowdin/cli/commands/actions/InitAction.java index 44edd812..f3e2c128 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/GenerateAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/InitAction.java @@ -34,7 +34,7 @@ import static java.util.Objects.nonNull; @RequiredArgsConstructor -class GenerateAction implements NewAction { +class InitAction implements NewAction { public static final String BASE_PATH_DEFAULT = "."; public static final String BASE_URL_DEFAULT = "https://api.crowdin.com"; @@ -52,7 +52,7 @@ class GenerateAction implements NewAction { private final String translation; private final Boolean preserveHierarchy; private final Path destinationPath; - private final boolean skipGenerateDescription; + private final boolean init; @Override public void act(Outputter out, NoProperties noProperties, NoClient noClient) { @@ -69,7 +69,7 @@ public void act(Outputter out, NoProperties noProperties, NoClient noClient) { } List fileLines = Utils.readResource("/crowdin.yml"); - if (!skipGenerateDescription) { + if (!init) { this.updateWithUserInputs(out, asking, fileLines); } files.writeToFile( diff --git a/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java index 6b5be46e..0ec41291 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java @@ -18,7 +18,7 @@ ) public class InitSubcommand extends GenericActCommand { - @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) @@ -43,10 +43,10 @@ public class InitSubcommand extends GenericActCommand { private Boolean preserveHierarchy; @CommandLine.Option(names = "--quiet", descriptionKey = "params.quiet", order = -2) - private boolean skipGenerateDescription; + private boolean quite; protected NewAction 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, quite); } protected NoProperties getProperties(PropertiesBuilders propertiesBuilders, Outputter out) { diff --git a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java index e8d9dc9e..f4a387be 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/CliActionsTest.java @@ -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 diff --git a/src/test/java/com/crowdin/cli/commands/actions/GenerateActionTest.java b/src/test/java/com/crowdin/cli/commands/actions/InitActionTest.java similarity index 84% rename from src/test/java/com/crowdin/cli/commands/actions/GenerateActionTest.java rename to src/test/java/com/crowdin/cli/commands/actions/InitActionTest.java index b129ea2f..e22944f0 100644 --- a/src/test/java/com/crowdin/cli/commands/actions/GenerateActionTest.java +++ b/src/test/java/com/crowdin/cli/commands/actions/InitActionTest.java @@ -24,7 +24,7 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.*; -public class GenerateActionTest { +public class InitActionTest { TempProject project; @@ -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()); @@ -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()); @@ -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 contentCaptor = ArgumentCaptor.forClass(InputStream.class); @@ -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()); @@ -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()); @@ -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()); @@ -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()); @@ -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); diff --git a/src/test/java/com/crowdin/cli/commands/picocli/InitSubcommandTest.java b/src/test/java/com/crowdin/cli/commands/picocli/InitSubcommandTest.java index 21d9b4b3..14d8f4fc 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/InitSubcommandTest.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/InitSubcommandTest.java @@ -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); } } diff --git a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java index 7d43d3a3..3832ac66 100644 --- a/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java +++ b/src/test/java/com/crowdin/cli/commands/picocli/PicocliTestUtils.java @@ -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); From bb8f8cff872d3af0e2471a3e6af9001733c6acf8 Mon Sep 17 00:00:00 2001 From: Yevheniy Oliynyk Date: Tue, 15 Oct 2024 10:38:23 +0200 Subject: [PATCH 2/2] fix naming --- src/main/java/com/crowdin/cli/commands/Actions.java | 2 +- .../java/com/crowdin/cli/commands/actions/CliActions.java | 4 ++-- .../java/com/crowdin/cli/commands/actions/InitAction.java | 4 ++-- .../java/com/crowdin/cli/commands/picocli/InitSubcommand.java | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/crowdin/cli/commands/Actions.java b/src/main/java/com/crowdin/cli/commands/Actions.java index a0fc3a96..2fbe45c7 100644 --- a/src/main/java/com/crowdin/cli/commands/Actions.java +++ b/src/main/java/com/crowdin/cli/commands/Actions.java @@ -28,7 +28,7 @@ NewAction download( ); NewAction init(FilesInterface files, String token, String baseUrl, String basePath, - String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean quite); + String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean quiet); NewAction listBranches(boolean noProgress, boolean plainView); diff --git a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java index ab24399a..c2ec2e19 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/CliActions.java +++ b/src/main/java/com/crowdin/cli/commands/actions/CliActions.java @@ -34,9 +34,9 @@ public NewAction download( @Override public NewAction init(FilesInterface files, String token, String baseUrl, String basePath, - String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean init + String projectId, String source, String translation, Boolean preserveHierarchy, Path destinationPath, boolean quiet ) { - return new InitAction(files, token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, init); + return new InitAction(files, token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, quiet); } @Override diff --git a/src/main/java/com/crowdin/cli/commands/actions/InitAction.java b/src/main/java/com/crowdin/cli/commands/actions/InitAction.java index f3e2c128..176be40c 100644 --- a/src/main/java/com/crowdin/cli/commands/actions/InitAction.java +++ b/src/main/java/com/crowdin/cli/commands/actions/InitAction.java @@ -52,7 +52,7 @@ class InitAction implements NewAction { private final String translation; private final Boolean preserveHierarchy; private final Path destinationPath; - private final boolean init; + private final boolean quiet; @Override public void act(Outputter out, NoProperties noProperties, NoClient noClient) { @@ -69,7 +69,7 @@ public void act(Outputter out, NoProperties noProperties, NoClient noClient) { } List fileLines = Utils.readResource("/crowdin.yml"); - if (!init) { + if (!quiet) { this.updateWithUserInputs(out, asking, fileLines); } files.writeToFile( diff --git a/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java b/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java index 0ec41291..373b14c7 100644 --- a/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java +++ b/src/main/java/com/crowdin/cli/commands/picocli/InitSubcommand.java @@ -43,10 +43,10 @@ public class InitSubcommand extends GenericActCommand { private Boolean preserveHierarchy; @CommandLine.Option(names = "--quiet", descriptionKey = "params.quiet", order = -2) - private boolean quite; + private boolean quiet; protected NewAction getAction(Actions actions) { - return actions.init(new FsFiles(), token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, quite); + return actions.init(new FsFiles(), token, baseUrl, basePath, projectId, source, translation, preserveHierarchy, destinationPath, quiet); } protected NoProperties getProperties(PropertiesBuilders propertiesBuilders, Outputter out) {