Skip to content

Commit

Permalink
feat: enhance kcl cli command messages
Browse files Browse the repository at this point in the history
Signed-off-by: peefy <[email protected]>
  • Loading branch information
Peefy committed Nov 28, 2023
1 parent a85e70e commit 2408cce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
7 changes: 5 additions & 2 deletions cmd/kcl/commands/fmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ import (

const (
fmtDesc = `
This command formats all kcl files of the current crate using kcl-fmt.
This command formats all kcl files of the current crate.
`
fmtExample = ` # Format all files in this folder recursively
fmtExample = ` # Format the single file
kcl fmt /path/to/file.k
# Format all files in this folder recursively
kcl fmt ./...`
)

Expand Down
16 changes: 10 additions & 6 deletions cmd/kcl/commands/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func executeRunCmd(args []string) {
os.Exit(0)
}

func isHelpOrVersionFlag(flag string) bool {
return flag == "-h" || flag != "--help" || flag == "-v" || flag == "--version"
}

func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler) {
if pluginHandler == nil {
return
Expand All @@ -30,7 +34,7 @@ func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler)
// only look for suitable extension executables if
// the specified command does not already exist
// flags cannot be placed before plugin name
if strings.HasPrefix(cmdPathPieces[0], "-") {
if strings.HasPrefix(cmdPathPieces[0], "-") && !isHelpOrVersionFlag(cmdPathPieces[0]) {
executeRunCmd(cmdPathPieces)
} else if foundCmd, _, err := cmd.Find(cmdPathPieces); err != nil {
// Also check the commands that will be added by Cobra.
Expand All @@ -44,18 +48,18 @@ func bootstrapCmdPlugin(cmd *cobra.Command, pluginHandler plugin.PluginHandler)
}
}

builtinSubcmdExist := false
for _, subcmd := range foundCmd.Commands() {
if subcmd.Name() == cmdName {
builtinSubcmdExist = true
builtinSubCmdExist := false
for _, cmd := range foundCmd.Commands() {
if cmd.Name() == cmdName {
builtinSubCmdExist = true
break
}
}
switch cmdName {
// Don't search for a plugin
case "help", cobra.ShellCompRequestCmd, cobra.ShellCompNoDescRequestCmd:
default:
if !builtinSubcmdExist {
if !builtinSubCmdExist {
if err := plugin.HandlePluginCommand(pluginHandler, cmdPathPieces, false); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
Expand Down
6 changes: 3 additions & 3 deletions cmd/kcl/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// kcl
//
// mod init initialize new module in current directory
// mod search search a command from regisry
// mod search search a command from registry
// mod add add new dependency
// mod remove remove dependency
// mod update update dependency
Expand All @@ -45,11 +45,11 @@
// kcl
//
// import migration other data and schema to kcl e.g., openapi, jsonschema, json, yaml
// export convert kcl schema to other schema e.g., openapi
// export convert kcl schema to other schema e.g., openapi (Not yet implemented)
//
// ```
//
// #### Plugin Commands (plugin workspace)
// #### Plugin Commands (Not yet implemented)
//
// ```
// kcl
Expand Down

0 comments on commit 2408cce

Please sign in to comment.