Skip to content
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

add "init templates" cmd, used to list templates in format #334

Merged
merged 1 commit into from
May 10, 2023

Conversation

healthjyk
Copy link
Contributor

What type of PR is this?

feature

What this PR does / why we need it:

list init templates from local or online, support json format. Hence, user can parse the specific elements of the templates.

Which issue(s) this PR fixes:

Fixes #265

Special notes for your reviewer:

If the cmd failed, the output is not in json format, even if "--output=json" is specified.

Does this PR introduce a user-facing change?

None

Additional documentation e.g., design docs, usage docs, etc.:

kusion init templates command helps you get the templates which are used to generate a scaffolding KCL project.
Here are the examples:
# Get name and description of internal templates
  kusion init templates
# Get templates from specific templates location, and output in json format
  kusion init templates https://github.com/<user>/<repo> --online=true --output=json

@github-actions
Copy link

github-actions bot commented May 6, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@healthjyk
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@SparkYuan
Copy link
Member

@healthjyk please add an example output for this command

@healthjyk
Copy link
Contributor Author

healthjyk commented May 8, 2023

@healthjyk please add an example output for this command

an successful request is like:

[
    {
        "dir": "/${userName}/.kusionup/current/templates/external/code-city",
        "name": "code-city",
        "projectName": "code-city",
        "description": "Code City metaphor for visualizing Go source code in 3D.",
        "quickstart": "kusion compile main.k -Y ci-test/settings.yaml",
        "projectFields": [
            {
                "name": "AppName",
                "description": "App name. Default to 'gocity'.",
                "type": "string",
                "default": "gocity"
            },
            {
                "name": "ContainerPort",
                "description": "The number of port to expose on the container's IP address.",
                "type": "int",
                "default": 4000
            },
            {
                "name": "ServicePort",
                "description": "The port that will be exposed by this service.",
                "type": "int",
                "default": 4000
            }
        ],
        "stacks": [
            {
                "name": "dev",
                "fields": [
                    {
                        "name": "Image",
                        "description": "Docker image address of gocity. Default to 'yuanhao1223/gocity:latest'.",
                        "type": "string",
                        "default": "howieyuen/gocity:latest"
                    }
                ]
            }
        ]
    }
]

pkg/cmd/init/init.go Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented May 8, 2023

Pull Request Test Coverage Report for Build 4915161384

  • 102 of 153 (66.67%) changed or added relevant lines in 2 files are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage increased (+0.08%) to 71.913%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/cmd/init/init.go 18 27 66.67%
pkg/cmd/init/options.go 84 126 66.67%
Files with Coverage Reduction New Missed Lines %
pkg/cmd/init/options.go 2 69.9%
Totals Coverage Status
Change from base Build 4913825402: 0.08%
Covered Lines: 4857
Relevant Lines: 6754

💛 - Coveralls

@amyXia1994
Copy link
Contributor

The error message should output to stderr, but now the wrong git repo url will result in an error ouput in stdout. :
kusion init templates https://github.com/KusionStack/no-exist --online=true -o json
❌ no templates

kusion init templates KusionStack/kusion-templates.git --online=true -o json
❌ template 'kusionstack/kusion-templates.git' not found

kusion init templates https://github.com/kusion-templates.git --online=true -o json
❌ failed to retrieve git folder: invalid Git URL

@amyXia1994
Copy link
Contributor

I'll merge this PR. please resolve the stderr and subcommand name problems in a separate PR.

@amyXia1994 amyXia1994 merged commit 621db5f into KusionStack:main May 10, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2023
@healthjyk healthjyk deleted the init-template-list branch December 27, 2023 03:33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request] Kusion provides API for integration tools
5 participants