Skip to content

Commit 0cdfda3

Browse files
authored
Merge pull request #1 from Peefy/initial-cli
[WIP] feat: init kcl cli projects.
2 parents e479f14 + 14196f3 commit 0cdfda3

File tree

24 files changed

+2079
-2
lines changed

24 files changed

+2079
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Reference from:
2+
# https://github.com/c-bata/go-prompt/blob/master/.github/workflows/test.yml
3+
name: CI
4+
on: [push, pull_request]
5+
6+
jobs:
7+
Test:
8+
name: Unit tests with coverage
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v2
13+
with:
14+
fetch-depth: 0
15+
- name: Set up Go 1.19
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: 1.19
19+
20+
- run: make lint
21+
22+
- name: Running go tests with coverage
23+
env:
24+
GO111MODULE: on
25+
run: |
26+
make cover
27+
- name: Send coverage
28+
uses: shogo82148/actions-goveralls@v1
29+
with:
30+
path-to-profile: coverage.out
31+
32+
Lint:
33+
name: Lint checks
34+
runs-on: ubuntu-latest
35+
steps:
36+
- name: Checkout
37+
uses: actions/checkout@v2
38+
with:
39+
fetch-depth: 0
40+
- name: Set up Go 1.19
41+
uses: actions/setup-go@v2
42+
with:
43+
go-version: 1.19
44+
- name: golangci-lint
45+
uses: golangci/golangci-lint-action@v3
46+
with:
47+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
48+
version: v1.50.1

.github/workflows/cla.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "CLA Assistant"
2+
on:
3+
issue_comment:
4+
types: [created]
5+
pull_request_target:
6+
types: [opened,closed,synchronize]
7+
8+
jobs:
9+
CLAssistant:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: "CLA Assistant"
13+
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have read the CLA Document and I hereby sign the CLA') || github.event_name == 'pull_request_target'
14+
# Beta Release
15+
uses: cla-assistant/[email protected]
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
# the below token should have repo scope and must be manually added by you in the repository's secret
19+
PERSONAL_ACCESS_TOKEN : ${{ secrets.KCL_LANG_BOT_TOKEN }}
20+
with:
21+
path-to-document: 'https://github.com/kcl-lang/.github/blob/main/CLA.md' # e.g. a CLA or a DCO document
22+
23+
# branch should not be protected
24+
lock-pullrequest-aftermerge: True
25+
path-to-signatures: 'signatures/version1/cla.json'
26+
remote-organization-name: kcl-lang
27+
remote-repository-name: cla.db
28+
branch: 'main'
29+
allowlist: 'test'
30+
31+
#below are the optional inputs - If the optional inputs are not given, then default values will be taken
32+
#remote-organization-name: enter the remote organization name where the signatures should be stored (Default is storing the signatures in the same repository)
33+
#remote-repository-name: enter the remote repository name where the signatures should be stored (Default is storing the signatures in the same repository)
34+
#create-file-commit-message: 'For example: Creating file for storing CLA Signatures'
35+
#signed-commit-message: 'For example: $contributorName has signed the CLA in #$pullRequestNo'
36+
#custom-notsigned-prcomment: 'pull request comment with Introductory message to ask new contributors to sign'
37+
#custom-pr-sign-comment: 'The signature to be committed in order to sign the CLA'
38+
#custom-allsigned-prcomment: 'pull request comment when all contributors has signed, defaults to **CLA Assistant Lite bot** All Contributors have signed the CLA.'
39+
#lock-pullrequest-aftermerge: false - if you don't want this bot to automatically lock the pull request after merging (default - true)
40+
#use-dco-flag: true - If you are using DCO instead of CLA

.github/workflows/release.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Reference from:
2+
# https://goreleaser.com/ci/actions/
3+
name: Release
4+
on:
5+
push:
6+
tags:
7+
- "v*"
8+
permissions:
9+
contents: write
10+
jobs:
11+
Publish:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- name: Set up Go
19+
uses: actions/setup-go@v2
20+
with:
21+
go-version: 1.19
22+
- name: Run GoReleaser
23+
uses: goreleaser/goreleaser-action@v4
24+
with:
25+
distribution: goreleaser
26+
version: latest
27+
args: release --clean
28+
env:
29+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@
1919

2020
# Go workspace file
2121
go.work
22+
23+
build/
24+
.vscode/
25+
.kclvm/
26+
27+
.DS_store

.goreleaser.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# This is an example .goreleaser.yml file with some sane defaults.
2+
# Make sure to check the documentation at http://goreleaser.com
3+
before:
4+
hooks:
5+
# You may remove this if you don't use go modules.
6+
- go mod tidy
7+
8+
# .goreleaser.yml
9+
builds:
10+
- id: "kcl"
11+
main: ./kcl.go
12+
goos:
13+
- darwin
14+
- linux
15+
- windows
16+
goarch:
17+
- amd64
18+
- arm64
19+
env:
20+
- CGO_ENABLED=0
21+
ldflags:
22+
- "-X kcl-lang.io/cli/pkg/version.version={{.Version}}"

README-zh.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<h1 align="center">KCL Command Line Interface (CLI)</h1>
2+
3+
<p align="center">
4+
<a href="./README.md">English</a> | <a href="./README-zh.md">简体中文</a>
5+
</p>
6+
<p align="center">
7+
<a href="#介绍">介绍</a> | <a href="#安装">安装</a> | <a href="#快速开始">快速开始</a>
8+
</p>
9+
10+
11+
<p align="center">
12+
<img src="https://coveralls.io/repos/github/kcl-lang/cli/badge.svg">
13+
<img src="https://img.shields.io/badge/license-Apache--2.0-green">
14+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen">
15+
</p>
16+
17+
## 介绍
18+
19+
`kcl` 是一个命令行界面,包括语言核心功能、IDE功能、包管理工具、社区集成和其他工具等。
20+
21+
## 安装
22+
23+
### 使用脚本安装
24+
25+
### 使用 `go install` 安装
26+
27+
您可以使用 `go install` 命令安装 `kcl`
28+
29+
```shell
30+
go install kcl-lang.io/cli@latest
31+
```
32+
33+
### 从 Github Release 页面手动安装
34+
35+
您也可以从 Github Release 中获取 `kcl` ,并将 `kcl` 的二进制文件路径设置到环境变量 PATH 中。
36+
37+
```shell
38+
# KCL_INSTALLATION_PATH 是 `kcl` 二进制文件的所在目录.
39+
export PATH=$KCL_INSTALLATION_PATH:$PATH
40+
```
41+
42+
请使用以下命令以确保您成功安装了 `kcl`
43+
44+
```shell
45+
kcl --help
46+
```
47+
48+
### 从源代码构建
49+
50+
## 快速开始
51+
52+
```shell
53+
kcl run ./examples/kubernetes.k
54+
```
55+
56+
## 常见问题 (FAQ)
57+
58+
##### Q: 我在使用 `go install` 安装 `kcl` 后,出现了 `command not found` 的错误。
59+
60+
A: `go install` 默认会将二进制文件安装到 `$GOPATH/bin` 目录下,您需要将 `$GOPATH/bin` 添加到环境变量 `PATH` 中。

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
# cli
2-
The KCL Command Line Interface (CLI)
1+
<h1 align="center">KCL CLI</h1>
2+
3+
<p align="center">
4+
<a href="./README.md">English</a> | <a href="./README-zh.md">简体中文</a>
5+
</p>
6+
<p align="center">
7+
<a href="#introduction">Introduction</a> | <a href="#installation">Installation</a> | <a href="#quick-start">Quick start</a>
8+
</p>
9+
10+
<p align="center">
11+
<img src="https://coveralls.io/repos/github/kcl-lang/cli/badge.svg">
12+
<img src="https://img.shields.io/badge/license-Apache--2.0-green">
13+
<img src="https://img.shields.io/badge/PRs-welcome-brightgreen">
14+
</p>
15+
16+
## Introduction
17+
18+
`kcl` is the KCL package manager. `KCL CLI` downloads your KCL package's dependencies, compiles your KCL packages, makes packages, and uploads them to the kcl package registry.
19+
20+
## Installation
21+
22+
### Scripts
23+
24+
### Go install
25+
26+
You can download `kcl` via `go install`.
27+
28+
```shell
29+
go install kcl-lang.io/cli@latest
30+
```
31+
32+
### Download from GITHUB Release Page
33+
34+
You can also get `kcl` from the github release and set the binary path to the environment variable PATH.
35+
36+
```shell
37+
# KCL CLI_INSTALLATION_PATH is the path of the `KCL CLI` binary.
38+
export PATH=$KCL CLI_INSTALLATION_PATH:$PATH
39+
```
40+
41+
Use the following command to ensure that you install `kcl` successfully.
42+
43+
```shell
44+
kcl --help
45+
```
46+
47+
### Build from Source Code
48+
49+
## Quick Start
50+
51+
```shell
52+
kcl run ./examples/kubernetes.k
53+
```
54+
55+
## Frequently Asked Questions (FAQ)
56+
57+
### Q: I am using `go install` to install `kcl`, but I get the error `command not found`.
58+
59+
- A: `go install` will install the binary file to `$GOPATH/bin` by default. You need to add `$GOPATH/bin` to the environment variable `PATH`.
60+
61+
## Learn More
62+
63+
- [KCL Website](https://kcl-lang.io)

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.7.0-alpha.1

cmd/root.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
// #### Language & Tooling Commands
2+
//
3+
// ```
4+
// kcl
5+
//
6+
// run compile kcl package from a url or filepath
7+
// build build the kcl package
8+
// check check the current package, but don't build target files
9+
// doc documentation tool
10+
// fmt format tool
11+
// lint lint tool
12+
// test unit/integration/benchmark test tool
13+
// lsp language server tool
14+
// clean remove object files and cached files
15+
//
16+
// ```
17+
//
18+
// #### Package & Registry Related Commands (mod and registry workspace)
19+
//
20+
// ```
21+
// kcl
22+
//
23+
// mod init initialize new module in current directory
24+
// mod search search a command from regisry
25+
// mod add add new dependency
26+
// mod remove remove dependency
27+
// mod update update dependency
28+
// mod pkg package a kcl package into tar
29+
// mod metadata output the resolved dependencies of a package
30+
// mod push push kcl package to OCI registry.
31+
// mod pull pull kcl package from OCI registry.
32+
// registry login login to a registry
33+
// registry logout logout from a registry
34+
//
35+
// ```
36+
//
37+
// #### Integration Commands
38+
//
39+
// ```
40+
// kcl
41+
//
42+
// import migration other data and schema to kcl e.g., openapi, jsonschema, json, yaml
43+
// export convert kcl schema to other schema e.g., openapi
44+
//
45+
// ```
46+
//
47+
// #### Plugin Commands (plugin workspace)
48+
//
49+
// ```
50+
// kcl
51+
//
52+
// plugin install install one or more kcl command plugins
53+
// plugin list list installed command plugins
54+
// plugin uninstall uninstall one or more command plugins
55+
// plugin update update one or more command plugins
56+
//
57+
// ```
58+
//
59+
// #### Version and Help Commands
60+
//
61+
// ```
62+
// kcl
63+
//
64+
// help, h Shows a list of commands or help for one command
65+
// version Shows the command version
66+
//
67+
// ```
68+
package cmd
69+
70+
import (
71+
"github.com/spf13/cobra"
72+
)
73+
74+
const rootCmdShortUsage = "The KCL Command Line Interface (CLI)."
75+
const rootCmdLongUsage = `The KCL Command Line Interface (CLI).
76+
77+
KCL is an open-source, constraint-based record and functional language that
78+
enhances the writing of complex configurations, including those for cloud-native
79+
scenarios. The KCL website: https://kcl-lang.io
80+
`
81+
82+
// New creates a new cobra client
83+
func New() *cobra.Command {
84+
cmd := &cobra.Command{
85+
Use: "kcl",
86+
Short: rootCmdShortUsage,
87+
Long: rootCmdLongUsage,
88+
SilenceUsage: true,
89+
}
90+
cmd.AddCommand(NewVersionCmd())
91+
cmd.AddCommand(NewRunCmd())
92+
cmd.SetHelpCommand(&cobra.Command{}) // Disable the help command
93+
return cmd
94+
}

0 commit comments

Comments
 (0)