Skip to content
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
16 changes: 1 addition & 15 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# -----------------------------
# Go / Build / Binary files
# -----------------------------
*.o
*.a
*.so
Expand All @@ -15,9 +13,7 @@ cobra.test
bin/
dist/

# -----------------------------
# Project specific / temporary
# -----------------------------
output.json
output.yaml
output.xml
Expand All @@ -31,9 +27,7 @@ config.yaml
# pkg/prompt folder (included for interactive prompts)
# pkg/prompt/ <- commented out so files are tracked

# -----------------------------
# IDE / Editor
# -----------------------------
.idea/
.vscode/
*.iml
Expand All @@ -42,20 +36,12 @@ Session.vim
.netrwhist
*~

# -----------------------------
# Other generated files / folders
# -----------------------------
# Generated binaries and build outputs
codewise-cli
myapp/
myapp/codewise
codewise
myappcodewise-cli
codewise-cli
JTY_output.yaml
KVTJ_output.json
YTJ_output.json

# -----------------------------
# Environment files
# -----------------------------
.env
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,23 @@ helm/chart/
Usage:

```bash
codewise encode --input file --output out --type <mode>
codewise encode --input file --output out [flags]
```

Supported modes:
Common conversions:

| mode | description |
| ------ | ------------- |
| `JTY` | JSON → YAML |
| `YTJ` | YAML → JSON |
| `KVTJ` | .env → JSON |
| `B64E` | Base64 encode |
| `B64D` | Base64 decode |
| command example | description |
| --------------- | ----------- |
| `codewise encode -i app.json -o app.yaml --json-to-yaml` | JSON → YAML |
| `codewise encode -i app.yaml -o app.json` | YAML → JSON (default path) |
| `codewise encode -i .env -o env.json --env-to-json` | .env → JSON |
| `codewise encode -i input.txt -o encoded.txt --base64` | Base64 encode |
| `codewise encode -i encoded.txt -o output.txt --base64 --decode` | Base64 decode |

Additional auto-detected conversions are supported from file extensions:

- TOML ⇄ JSON
- XML ⇄ JSON

---

Expand Down
23 changes: 6 additions & 17 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"

"github.com/aryansharma9917/codewise-cli/pkg/deploy"
"github.com/spf13/cobra"
Expand All @@ -20,32 +19,22 @@ var deployCmd = &cobra.Command{
var deployRunCmd = &cobra.Command{
Use: "run",
Short: "Execute deployment",
Run: func(cmd *cobra.Command, args []string) {

RunE: func(cmd *cobra.Command, args []string) error {
if deployEnv == "" {
fmt.Println("please provide --env")
return
}

if err := deploy.Run(deployEnv, dryRun); err != nil {
fmt.Println("deploy error:", err)
return ExitError("please provide --env")
}
return deploy.Run(deployEnv, dryRun)
},
}

var deployPlanCmd = &cobra.Command{
Use: "plan",
Short: "Preview deployment execution plan",
Run: func(cmd *cobra.Command, args []string) {

RunE: func(cmd *cobra.Command, args []string) error {
if deployEnv == "" {
fmt.Println("please provide --env")
return
}

if err := deploy.Plan(deployEnv); err != nil {
fmt.Println("plan error:", err)
return ExitError("please provide --env")
}
return deploy.Plan(deployEnv)
},
}

Expand Down
20 changes: 11 additions & 9 deletions cmd/doctor.go → cmd/docker.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"

"github.com/aryansharma9917/codewise-cli/pkg/docker"
"github.com/spf13/cobra"
Expand All @@ -17,32 +16,35 @@ var dockerCmd = &cobra.Command{
var dockerInitCmd = &cobra.Command{
Use: "init",
Short: "Generate a Dockerfile",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
if err := docker.InitDockerfile(); err != nil {
fmt.Println("ℹ️", err.Error())
return
return LogError(err.Error())
}
fmt.Println("✅ Dockerfile created")
LogSuccess("Dockerfile created")
return nil
},
}

var dockerValidateCmd = &cobra.Command{
Use: "validate",
Short: "Validate Dockerfile best practices",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
if err := docker.ValidateDockerfile(); err != nil {
fmt.Println("❌", err.Error())
return LogError(err.Error())
}
return nil
},
}

var dockerBuildCmd = &cobra.Command{
Use: "build",
Short: "Build Docker image",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
if err := docker.BuildDockerImage(imageTag); err != nil {
fmt.Println("❌ Docker build failed")
return LogError("Docker build failed: %v", err)
}
LogSuccess("Docker image built successfully")
return nil
},
}

Expand Down
15 changes: 7 additions & 8 deletions cmd/env_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,22 @@ var envCreateCmd = &cobra.Command{
Use: "create <name>",
Short: "Create a new environment",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]

if interactive {
if err := createEnvInteractive(name); err != nil {
fmt.Println("error:", err)
return
return LogError("error: %v", err)
}
fmt.Println("environment", name, "created")
return
LogSuccess("environment %s created", name)
return nil
}

if err := env.CreateEnv(name, env.CreateOptions{}); err != nil {
fmt.Println("error:", err)
return
return LogError("error: %v", err)
}
fmt.Println("environment", name, "created")
LogSuccess("environment %s created", name)
return nil
},
}

Expand Down
14 changes: 6 additions & 8 deletions cmd/env_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var envDeleteCmd = &cobra.Command{
Use: "delete <name>",
Short: "Delete an environment",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
name := args[0]

if !yes {
Expand All @@ -23,21 +23,19 @@ var envDeleteCmd = &cobra.Command{
Message: fmt.Sprintf("Delete environment %q?", name),
}
if err := survey.AskOne(prompt, &confirm); err != nil {
fmt.Println("error:", err)
return
return LogError("error: %v", err)
}
if !confirm {
fmt.Println("aborted")
return
return LogError("aborted")
}
}

if err := env.DeleteEnv(name, env.DeleteOptions{Force: yes}); err != nil {
fmt.Println("error:", err)
return
return LogError("error: %v", err)
}

fmt.Println("environment", name, "deleted")
LogSuccess("environment %s deleted", name)
return nil
},
}

Expand Down
42 changes: 21 additions & 21 deletions cmd/env_list.go
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package cmd

import (
"fmt"
"fmt"

"github.com/aryansharma9917/codewise-cli/pkg/env"
"github.com/spf13/cobra"
"github.com/aryansharma9917/codewise-cli/pkg/env"
"github.com/spf13/cobra"
)

var envListCmd = &cobra.Command{
Use: "list",
Short: "List environments",
Run: func(cmd *cobra.Command, args []string) {
envs, err := env.ListEnvs()
if err != nil {
fmt.Println("error:", err)
return
}
Use: "list",
Short: "List environments",
RunE: func(cmd *cobra.Command, args []string) error {
envs, err := env.ListEnvs()
if err != nil {
return LogError(err.Error())
}

if len(envs) == 0 {
fmt.Println("no environments found")
return
}
if len(envs) == 0 {
fmt.Println("no environments found")
return nil
}

for _, e := range envs {
fmt.Printf("%-10s namespace=%s context=%s\n",
e.Name, e.K8s.Namespace, e.K8s.Context)
}
},
for _, e := range envs {
fmt.Printf("%-10s namespace=%s context=%s\n",
e.Name, e.K8s.Namespace, e.K8s.Context)
}
return nil
},
}

func init() {
envCmd.AddCommand(envListCmd)
envCmd.AddCommand(envListCmd)
}
29 changes: 29 additions & 0 deletions cmd/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"fmt"
"os"
)

// ExitError prints an error message and exits with status code 1.
func ExitError(format string, args ...interface{}) error {
fmt.Fprintf(os.Stderr, "error: %s\n", fmt.Sprintf(format, args...))
return fmt.Errorf(format, args...)
}

// LogError prints an info/warning message but does not exit.
func LogError(format string, args ...interface{}) error {
msg := fmt.Sprintf(format, args...)
fmt.Fprintf(os.Stderr, "info: %s\n", msg)
return fmt.Errorf(msg)
}

// LogInfo prints an info message to stderr.
func LogInfo(format string, args ...interface{}) {
fmt.Fprintf(os.Stderr, "info: %s\n", fmt.Sprintf(format, args...))
}

// LogSuccess prints a success message to stdout.
func LogSuccess(format string, args ...interface{}) {
fmt.Printf("✅ %s\n", fmt.Sprintf(format, args...))
}
16 changes: 4 additions & 12 deletions cmd/k8s_apply.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
"fmt"

"github.com/aryansharma9917/codewise-cli/pkg/k8s"
"github.com/spf13/cobra"
Expand All @@ -16,23 +15,16 @@ var (
var k8sApplyCmd = &cobra.Command{
Use: "apply",
Short: "Apply Kubernetes manifests to the current cluster",
Run: func(cmd *cobra.Command, args []string) {
// If not a dry run, check cluster connectivity
RunE: func(cmd *cobra.Command, args []string) error {
if !k8sDryRun {
if err := k8s.CheckKubectl(); err != nil {
fmt.Println("info:", err.Error())
return
return LogError(err.Error())
}
if err := k8s.CheckCluster(); err != nil {
fmt.Println("info:", err.Error())
return
return LogError(err.Error())
}
}

if err := k8s.ApplyManifests(k8sNamespace, k8sContext, k8sDryRun); err != nil {
fmt.Println("info:", err.Error())
return
}
return k8s.ApplyManifests(k8sNamespace, k8sContext, k8sDryRun)
},
}

Expand Down
Loading
Loading