ballerina-lang
ballerina-lang copied to clipboard
Support passing package information when creating a new package
Description: $subject with bal new and init commands. Eg:
bal new myorg/mypackage:0.1.0 -t lib
bal new myorg/mypackage:0.1.0 -t choreo/gmail_new_attachment_to_drive:1.1.2
bal init myorg/mypackage:0.1.0
This document contains a simple analysis of the use of templates for project creation by other external tools. https://docs.google.com/document/d/1C7U2afAy8oaY_bXM2fXM5wVMHBllwNZbwkCLsBzr0HQ/edit?usp=sharing
Suggestions for the implementation
1. Provide an option to pass key, value pairs to override the configurations of the Ballerina.toml
Example
bal new myproj -t choreo/gmail:1.1.2 --package.name="myproj" --package.org="foo" --package.version="0.1.0"
bal new myproj -t choreo/gmail:1.1.2 --package.org="foo" --build-options.observabilityIncluded=true
bal new myproj -t choreo/gmail:1.1.2 --package.org="foo" --package.keywords=["io", "json"]
Notes
- The package name can be specified twice here. as a param and as a (key, value) pair again.
- Can use a
--key valueformat instead of--key=value. - We can implement to have simple parameters first and if needed can be extended to have more complex syntax like object arrays.
2. Provide the configurations as an object/ record.
Example
bal new myproj -t choreo/gmail:1.1.2 --config {package: {name:"myproj", org:"foo", version:"0.1.0"}
bal new myproj -t choreo/gmail:1.1.2 --config {package: {org:"foo", version:"0.1.0"}, build-options: {observabilityIncluded:true}}
bal new myproj -t choreo/gmail:1.1.2 --config {package: {org:"foo", keywords: ["io", "json"]}}
# f we need to include object arrays,
bal new myproj -t choreo/gmail:1.1.2 --config {package: {org:"foo"}, platform.java11.repository:[{path:"xx", scope:"testOnly", version:"1.0.1"}, {path:"yy", scope:"testOnly", version:"4.0.1"}]}
Notes
- Can use a suitable name instead of
configfor the flag. - Instead of
{key: "value"}format,{"key": "value"}format (similar to json) can be used. - Intuitive, but can be a bit complex for the user to manage the brackets in a terminal.
IMO, we can stick to the first option and for Update 3, let's get the implementation done for only the attributes of the table [package] in Ballerina.toml.
We can support the following formats for passing values to attributes in the [package] table
bal new myproj --package.name="myorg" --package.org="foo" --package.version="0.1.0"bal new -t <template> myproj --package.name="myorg" --package.org="foo" --package.version="0.1.0bal new -t <template> myproj --package.org="foo" --package.keywords=["io", "json"]
We should also support the following short form for providing just the org, name, and version as shown below
new foo --package=myorg/foo:0.1.0