Skip to content

Commit

Permalink
Simplify main.go
Browse files Browse the repository at this point in the history
  • Loading branch information
MacroPower committed Jan 4, 2025
1 parent 99dc675 commit 57b5098
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
20 changes: 2 additions & 18 deletions cmd/kclipper/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// Copyright The KCL Authors. All rights reserved.
//go:build cgo
// +build cgo

package main

Expand All @@ -15,9 +13,6 @@ import (

"github.com/MacroPower/kclipper/internal/cli"
"github.com/MacroPower/kclipper/pkg/log"
helmplugin "github.com/MacroPower/kclipper/pkg/plugin/helm"
httpplugin "github.com/MacroPower/kclipper/pkg/plugin/http"
osplugin "github.com/MacroPower/kclipper/pkg/plugin/os"
)

func init() {
Expand All @@ -44,28 +39,17 @@ The KCL website: https://kcl-lang.io
)

func main() {
if !envTrue("KCLX_HELM_PLUGIN_DISABLED") {
helmplugin.Register()
}
if !envTrue("KCLX_HTTP_PLUGIN_DISABLED") {
httpplugin.Register()
}
if !envTrue("KCLX_OS_PLUGIN_DISABLED") {
osplugin.Register()
}
cli.RegisterEnabledPlugins()

cmd := cli.NewRootCmd(cmdName, shortDesc, longDesc)
bootstrapCmdPlugin(cmd, plugin.NewDefaultPluginHandler([]string{cmdName}))

if err := cmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, strings.TrimLeft(err.Error(), "\n"))
os.Exit(1)
}
}

func envTrue(key string) bool {
return strings.ToLower(os.Getenv(key)) == "true"
}

// executeRunCmd the run command for the root command.
func executeRunCmd(args []string) {
cmd := kclcmd.NewRunCmd()
Expand Down
26 changes: 26 additions & 0 deletions internal/cli/plugins.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cli

import (
"os"
"strings"

helmplugin "github.com/MacroPower/kclipper/pkg/plugin/helm"
httpplugin "github.com/MacroPower/kclipper/pkg/plugin/http"
osplugin "github.com/MacroPower/kclipper/pkg/plugin/os"
)

func RegisterEnabledPlugins() {
if !envTrue("KCLX_HELM_PLUGIN_DISABLED") {
helmplugin.Register()
}
if !envTrue("KCLX_HTTP_PLUGIN_DISABLED") {
httpplugin.Register()
}
if !envTrue("KCLX_OS_PLUGIN_DISABLED") {
osplugin.Register()
}
}

func envTrue(key string) bool {
return strings.ToLower(os.Getenv(key)) == "true"
}

0 comments on commit 57b5098

Please sign in to comment.