-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the init command #336
Merged
Merged
Fix the init command #336
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4219da0
Fix the init command
Bhashinee 3128b14
Update the help content
Bhashinee 6c6c5a2
Update the help content
Bhashinee fc9c539
Merge branch 'init' of https://github.com/Bhashinee/persist-tools int…
Bhashinee 5a7297f
Address review suggestions
Bhashinee 48cc647
Address review suggestions
Bhashinee a15f4bb
Address review comments
Bhashinee 6e3c414
Update the add command help
Bhashinee 103a302
Update the help docs
Bhashinee bd317d3
Merge branch 'main' into init
Bhashinee d31fd83
Apply suggestions from code review
Bhashinee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
persist-cli-tests/src/test/java/io/ballerina/persist/tools/ToolingInitTest.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,78 @@ | ||
/* | ||
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). | ||
* | ||
* WSO2 LLC. licenses this file to you under the Apache License, | ||
* Version 2.0 (the "License"); you may not use this file except | ||
* in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package io.ballerina.persist.tools; | ||
|
||
import io.ballerina.persist.cmd.Init; | ||
import org.testng.annotations.Test; | ||
import picocli.CommandLine; | ||
|
||
import java.io.PrintStream; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static io.ballerina.persist.tools.utils.GeneratedSourcesTestUtils.assertGeneratedSources; | ||
|
||
public class ToolingInitTest { | ||
public static final String GENERATED_SOURCES_DIRECTORY = Paths.get("build", "generated-sources") | ||
.toString(); | ||
private static final PrintStream errStream = System.err; | ||
|
||
@Test(enabled = true) | ||
public void testInitWithDatastore() { | ||
executeInitCommand("tool_test_init_1", "mysql"); | ||
assertGeneratedSources("tool_test_init_1"); | ||
} | ||
|
||
@Test(enabled = true) | ||
public void testInitWithoutArguments() { | ||
executeInitCommand("tool_test_init_1"); | ||
assertGeneratedSources("tool_test_init_1"); | ||
} | ||
|
||
@Test(enabled = true) | ||
public void testInitWithBothDatastoreAndModule() { | ||
executeInitCommand("tool_test_init_1", "mysql", "test_module"); | ||
assertGeneratedSources("tool_test_init_1"); | ||
} | ||
|
||
public static void executeInitCommand(String subDir, String... args) { | ||
Class<?> persistClass; | ||
Path sourcePath = Paths.get(GENERATED_SOURCES_DIRECTORY, subDir); | ||
try { | ||
persistClass = Class.forName("io.ballerina.persist.cmd.Init"); | ||
Init persistCmd = (Init) persistClass.getDeclaredConstructor(String.class) | ||
.newInstance(sourcePath.toAbsolutePath().toString()); | ||
if (args.length > 1) { | ||
// ballerina persist init --datastore <datastore> --module <module> | ||
new CommandLine(persistCmd).parseArgs("--datastore", args[0], "--module", args[1]); | ||
} else if (args.length == 1) { | ||
// ballerina persist init --datastore <datastore> | ||
new CommandLine(persistCmd).parseArgs("--datastore", args[0]); | ||
} else { | ||
// ballerina persist init | ||
new CommandLine(persistCmd).parseArgs(); | ||
} | ||
persistCmd.execute(); | ||
} catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | ||
| InvocationTargetException e) { | ||
errStream.println(e.getMessage()); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,7 +11,7 @@ DESCRIPTION | |||||
data persistence in a Ballerina package. This step creates the required | ||||||
directories and configuration files. For example: | ||||||
|
||||||
$ bal persist init | ||||||
$ bal persist add | ||||||
|
||||||
Define the application's data model as the next step. Use the generated | ||||||
definition file in the "persist" directory to define the data model | ||||||
|
@@ -31,11 +31,25 @@ DESCRIPTION | |||||
Department department; | ||||||
|}; | ||||||
|
||||||
Then, generate the client API based on the data model. Use the generated | ||||||
API to query and manipulate the persistent data in the application. | ||||||
Then, generate the client API based on the data model. You can use the `bal build` command to generate the client. | ||||||
This process will automatically regenerate the client whenever you modify the data model during project builds. | ||||||
Use the generated API to query and manipulate the persistent data in the application. | ||||||
For example: | ||||||
|
||||||
$ bal persist generate | ||||||
$ bal build | ||||||
|
||||||
Apart from the above commands, the following commands are also available: | ||||||
|
||||||
$ bal persist init | ||||||
|
||||||
This command initializes the package for persistence and used in one time generation of the clients. | ||||||
Bhashinee marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
This command will create a new directory named 'persist' in the project directory. The 'persist' directory will | ||||||
contain empty model definition file which can be used to define the data model of the Ballerina project. | ||||||
|
||||||
$ bal persist generate --module persist --datastore mysql | ||||||
|
||||||
This command generates the client API based on the data model defined in the "persist" directory. Usually used | ||||||
for one time generation of the client. | ||||||
|
||||||
OPTIONS | ||||||
-h, --help | ||||||
|
@@ -44,7 +58,9 @@ OPTIONS | |||||
BALLERINA COMMANDS | ||||||
The below is a list of available subcommands: | ||||||
|
||||||
init Initialize the package for persistence | ||||||
add Initialize the package for persistence. Used along with `bal build` command. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed the suggestions in 103a302 |
||||||
init Initialize the package for persistence for one time code generation. Used along with | ||||||
`generate` command. | ||||||
Bhashinee marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
generate Generate the client API based on the data model defined in the "persist" directory | ||||||
|
||||||
Use 'bal persist <command> --help' for more information on a specific command. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to mention the options like above here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 48cc647