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

feat: add kclx CLI with plugins #120

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/kcl/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,13 @@ scenarios. The KCL website: https://kcl-lang.io

// New creates a new cobra client
func New() *cobra.Command {
return NewWithName(cmdName)
}

// NewWithName creates a new KCL CLI with the name
func NewWithName(name string) *cobra.Command {
cmd := &cobra.Command{
Use: cmdName,
Use: name,
Short: "The KCL Command Line Interface (CLI).",
Long: rootDesc,
SilenceUsage: true,
Expand Down
2 changes: 2 additions & 0 deletions cmd/kclx/examples/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
kclx main.k
3 changes: 3 additions & 0 deletions cmd/kclx/examples/main.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import kcl_plugin.hello

a = hello.add(1, 1)
Peefy marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 20 additions & 0 deletions cmd/kclx/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright The KCL Authors. All rights reserved.

package main

import (
"fmt"
"os"
"strings"

cmd "kcl-lang.io/cli/cmd/kcl/commands"
_ "kcl-lang.io/kcl-plugin/hello" // Import the hello plugin
_ "kcl-lang.io/kcl-plugin/http" // Import the http plugin
)

func main() {
if err := cmd.NewWithName("kclx").Execute(); err != nil {
fmt.Fprintln(os.Stderr, strings.TrimLeft(err.Error(), "\n"))
os.Exit(1)
}
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
github.com/spf13/cobra v1.8.1
kcl-lang.io/kcl-go v0.10.0-alpha.3
kcl-lang.io/kcl-openapi v0.6.6
kcl-lang.io/kcl-plugin v0.6.0
kcl-lang.io/kpm v0.10.0-alpha.1
)

Expand All @@ -19,6 +20,7 @@ require (
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.38.0 // indirect
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/aws/aws-sdk-go v1.44.122 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/chainguard-dev/git-urls v1.0.2 // indirect
Expand Down Expand Up @@ -53,6 +55,8 @@ require (
github.com/protocolbuffers/txtpbfmt v0.0.0-20240416193709-1e18ef0a7fdc // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.55.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuy
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190717042225-c3de453c63f4/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
Expand Down Expand Up @@ -928,6 +930,10 @@ github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ
github.com/ulikunitz/xz v0.5.10/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.55.0 h1:Zkefzgt6a7+bVKHnu/YaYSOPfNYNisSVBo/unVCf8k8=
github.com/valyala/fasthttp v1.55.0/go.mod h1:NkY9JtkrpPKmgwV3HTaS2HWaJss9RSIsRVfcxxoHiOM=
github.com/vbatts/tar-split v0.11.5 h1:3bHCTIheBm1qFTcgh9oPu+nNBtX+XJIupG/vacinCts=
github.com/vbatts/tar-split v0.11.5/go.mod h1:yZbwRsSeGjusneWgA781EKej9HF8vme8okylkAeNKLk=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
Expand Down Expand Up @@ -1688,6 +1694,8 @@ kcl-lang.io/kcl-go v0.10.0-alpha.3 h1:01grUuyy/XfBZDRoMqUesU6OdzVPk0WF9WDOvuY70Z
kcl-lang.io/kcl-go v0.10.0-alpha.3/go.mod h1:kfHDBqsLNT+9T6VorS/EVbriZzix1rjIq0w6WCJ7GbA=
kcl-lang.io/kcl-openapi v0.6.6 h1:iTsPTh1T6jDdwCKFFP6def9r66Sq8nAbATEbIL+XT+8=
kcl-lang.io/kcl-openapi v0.6.6/go.mod h1:Ai9mFztCVKkRSFabczO/r5hCNdqaNtAc2ZIRxTeV0Mk=
kcl-lang.io/kcl-plugin v0.6.0 h1:rBdoqKDPdOtojeOHCFnXoB/I7ltFjV61r0KkfOcL5sE=
kcl-lang.io/kcl-plugin v0.6.0/go.mod h1:LoIouleHYRKAvFcdW30yUlhsMYH2W9zD5Ji1XHfbht4=
kcl-lang.io/kpm v0.10.0-alpha.1 h1:HbrstASgJKIuKwCrhISXR0tvEP7jZAw21RYlejWNSx4=
kcl-lang.io/kpm v0.10.0-alpha.1/go.mod h1:nVh5Kmsq37czp8QTfnL3+uuko6lFOJNAATyEe/zlOXo=
kcl-lang.io/lib v0.10.0-alpha.3 h1:tZ7du+9/wv5ZHyPmPxljZQ33DdTYw++d9joH0LMC3q8=
Expand Down