Skip to content

Commit 2408cce

Browse files
committed
feat: enhance kcl cli command messages
Signed-off-by: peefy <xpf6677@163.com>
1 parent a85e70e commit 2408cce

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

cmd/kcl/commands/fmt.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ import (
1212

1313
const (
1414
fmtDesc = `
15-
This command formats all kcl files of the current crate using kcl-fmt.
15+
This command formats all kcl files of the current crate.
1616
`
17-
fmtExample = ` # Format all files in this folder recursively
17+
fmtExample = ` # Format the single file
18+
kcl fmt /path/to/file.k
19+
20+
# Format all files in this folder recursively
1821
kcl fmt ./...`
1922
)
2023

cmd/kcl/commands/plugin.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ func executeRunCmd(args []string) {
2020
os.Exit(0)
2121
}
2222

23+
func isHelpOrVersionFlag(flag string) bool {
24+
return flag == "-h" || flag != "--help" || flag == "-v" || flag == "--version"
25+
}
26+
2327
func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler) {
2428
if pluginHandler == nil {
2529
return
@@ -30,7 +34,7 @@ func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler)
3034
// only look for suitable extension executables if
3135
// the specified command does not already exist
3236
// flags cannot be placed before plugin name
33-
if strings.HasPrefix(cmdPathPieces[0], "-") {
37+
if strings.HasPrefix(cmdPathPieces[0], "-") && !isHelpOrVersionFlag(cmdPathPieces[0]) {
3438
executeRunCmd(cmdPathPieces)
3539
} else if foundCmd, _, err := cmd.Find(cmdPathPieces); err != nil {
3640
// Also check the commands that will be added by Cobra.
@@ -44,18 +48,18 @@ func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler)
4448
}
4549
}
4650

47-
builtinSubcmdExist := false
48-
for _, subcmd := range foundCmd.Commands() {
49-
if subcmd.Name() == cmdName {
50-
builtinSubcmdExist = true
51+
builtinSubCmdExist := false
52+
for _, cmd := range foundCmd.Commands() {
53+
if cmd.Name() == cmdName {
54+
builtinSubCmdExist = true
5155
break
5256
}
5357
}
5458
switch cmdName {
5559
// Don't search for a plugin
5660
case "help", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd:
5761
default:
58-
if !builtinSubcmdExist {
62+
if !builtinSubCmdExist {
5963
if err := plugin.HandlePluginCommand(pluginHandler, cmdPathPieces, false); err != nil {
6064
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
6165
os.Exit(1)

cmd/kcl/commands/root.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
// kcl
2727
//
2828
// mod init initialize new module in current directory
29-
// mod search search a command from regisry
29+
// mod search search a command from registry
3030
// mod add add new dependency
3131
// mod remove remove dependency
3232
// mod update update dependency
@@ -45,11 +45,11 @@
4545
// kcl
4646
//
4747
// import migration other data and schema to kcl e.g., openapi, jsonschema, json, yaml
48-
// export convert kcl schema to other schema e.g., openapi
48+
// export convert kcl schema to other schema e.g., openapi (Not yet implemented)
4949
//
5050
// ```
5151
//
52-
// #### Plugin Commands (plugin workspace)
52+
// #### Plugin Commands (Not yet implemented)
5353
//
5454
// ```
5555
// kcl

0 commit comments

Comments
 (0)