From 9d257f4065bd88fa090c1b478abdcf012c47c08d Mon Sep 17 00:00:00 2001 From: aryansharma9917 Date: Sat, 7 Feb 2026 15:31:12 +0530 Subject: [PATCH 1/2] Improve CLI UX by limiting banner to root command --- cmd/root.go | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 7af8a83..7221093 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,22 +10,32 @@ import ( var rootCmd = &cobra.Command{ Use: "codewise", Short: "CLI that helps you scaffold, encode, validate, and automate DevOps workflows easily.", - Long: `Codewise CLI v1.1.0 + Long: `Codewise CLI -This CLI helps you with common DevOps tasks like: -- JSON/YAML conversions -- Base64 encoding/decoding -- Dockerfile and Kubernetes manifest generation -- Project scaffolding and GitHub Actions template rendering +A powerful platform-style CLI for DevOps workflows including: + +• Environment-aware deployments +• Kubernetes orchestration +• Helm automation +• Docker tooling +• Template generation +• Encoding utilities `, + Run: func(cmd *cobra.Command, args []string) { + + // Banner ONLY when no subcommand is provided + PrintBanner() + + _ = cmd.Help() + }, Version: "v1.1.0", } // Execute runs the root command. func Execute() { - PrintBanner() + if err := rootCmd.Execute(); err != nil { - fmt.Println("❌", err) + fmt.Println("error:", err) os.Exit(1) } } @@ -40,5 +50,6 @@ func PrintBanner() { \____\___/ \__,_|\___/|_.__/ \__, | |___/ Codewise CLI - Simplify your DevOps + `) } From 6caee5d3eacfb4e286ff50c104c553dfc52d8739 Mon Sep 17 00:00:00 2001 From: aryansharma9917 Date: Sat, 7 Feb 2026 15:31:26 +0530 Subject: [PATCH 2/2] Add environment-aware deployment engine with executor and strategy resolution --- cmd/deploy.go | 37 ++++++++++++++++++++ pkg/deploy/deploy.go | 78 ++++++++++++++++++++++++++++++++++++++++++ pkg/deploy/executor.go | 30 ++++++++++++++++ pkg/deploy/loader.go | 17 +++++++++ pkg/deploy/resolver.go | 25 ++++++++++++++ 5 files changed, 187 insertions(+) create mode 100644 cmd/deploy.go create mode 100644 pkg/deploy/deploy.go create mode 100644 pkg/deploy/executor.go create mode 100644 pkg/deploy/loader.go create mode 100644 pkg/deploy/resolver.go diff --git a/cmd/deploy.go b/cmd/deploy.go new file mode 100644 index 0000000..621c68a --- /dev/null +++ b/cmd/deploy.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "fmt" + + "github.com/aryansharma9917/codewise-cli/pkg/deploy" + "github.com/spf13/cobra" +) + +var ( + deployEnv string + dryRun bool +) + +var deployCmd = &cobra.Command{ + Use: "deploy", + Short: "Deploy an application using the configured environment", + Run: func(cmd *cobra.Command, args []string) { + + if deployEnv == "" { + fmt.Println("please provide --env") + return + } + + if err := deploy.Run(deployEnv, dryRun); err != nil { + fmt.Println("deploy error:", err) + } + }, +} + +func init() { + + deployCmd.Flags().StringVar(&deployEnv, "env", "", "Environment to deploy") + deployCmd.Flags().BoolVar(&dryRun, "dry-run", false, "Preview deployment") + + rootCmd.AddCommand(deployCmd) +} diff --git a/pkg/deploy/deploy.go b/pkg/deploy/deploy.go new file mode 100644 index 0000000..2d519bb --- /dev/null +++ b/pkg/deploy/deploy.go @@ -0,0 +1,78 @@ +package deploy + +import ( + "fmt" + "os/exec" +) + +func checkDependency(name string) error { + + _, err := exec.LookPath(name) + if err != nil { + return fmt.Errorf("%s not found in PATH. please install it to continue", name) + } + + return nil +} + +func Run(envName string, dryRun bool) error { + + environment, err := LoadEnvironment(envName) + if err != nil { + return err + } + + strategy := ResolveStrategy(environment) + + executor := Executor{ + DryRun: dryRun, + } + + switch strategy { + + case StrategyHelm: + + if err := checkDependency("helm"); err != nil { + return err + } + + args := []string{ + "upgrade", + "--install", + environment.Helm.Release, + environment.Helm.Chart, + "--namespace", + environment.K8s.Namespace, + } + + // inject kube-context if provided + if environment.K8s.Context != "" { + args = append(args, "--kube-context", environment.K8s.Context) + } + + return executor.Run("helm", args...) + + case StrategyKubectl: + + if err := checkDependency("kubectl"); err != nil { + return err + } + + args := []string{ + "apply", + "-f", + "k8s/", + "-n", + environment.K8s.Namespace, + } + + if environment.K8s.Context != "" { + args = append(args, "--context", environment.K8s.Context) + } + + return executor.Run("kubectl", args...) + + default: + return fmt.Errorf("unknown deployment strategy") + } +} diff --git a/pkg/deploy/executor.go b/pkg/deploy/executor.go new file mode 100644 index 0000000..9daa047 --- /dev/null +++ b/pkg/deploy/executor.go @@ -0,0 +1,30 @@ +package deploy + +import ( + "fmt" + "os" + "os/exec" + "strings" +) + +type Executor struct { + DryRun bool +} + +func (e *Executor) Run(name string, args ...string) error { + + cmdStr := name + " " + strings.Join(args, " ") + + if e.DryRun { + fmt.Println("[dry-run]", cmdStr) + return nil + } + + cmd := exec.Command(name, args...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + fmt.Println("Running:", cmdStr) + + return cmd.Run() +} diff --git a/pkg/deploy/loader.go b/pkg/deploy/loader.go new file mode 100644 index 0000000..044eeb4 --- /dev/null +++ b/pkg/deploy/loader.go @@ -0,0 +1,17 @@ +package deploy + +import ( + "fmt" + + "github.com/aryansharma9917/codewise-cli/pkg/env" +) + +func LoadEnvironment(name string) (*env.Env, error) { + + e, err := env.LoadEnv(name) + if err != nil { + return nil, fmt.Errorf("failed to load environment: %w", err) + } + + return e, nil +} diff --git a/pkg/deploy/resolver.go b/pkg/deploy/resolver.go new file mode 100644 index 0000000..4c32878 --- /dev/null +++ b/pkg/deploy/resolver.go @@ -0,0 +1,25 @@ +package deploy + +import ( + "os" + "path/filepath" + + "github.com/aryansharma9917/codewise-cli/pkg/env" +) + +type Strategy string + +const ( + StrategyHelm Strategy = "helm" + StrategyKubectl Strategy = "kubectl" +) + +func ResolveStrategy(e *env.Env) Strategy { + + // check if helm chart exists + if _, err := os.Stat(filepath.Join(".", "helm", "chart")); err == nil { + return StrategyHelm + } + + return StrategyKubectl +}