diff --git a/PROJECT_OVERVIEW.md b/PROJECT_OVERVIEW.md new file mode 100644 index 0000000..7600bd9 --- /dev/null +++ b/PROJECT_OVERVIEW.md @@ -0,0 +1,116 @@ +# Codewise CLI Project Overview + +## What This Project Does + +Codewise CLI is a DevOps-focused command-line tool that unifies common workflows used in application delivery. + +It provides one command surface for: +- Dockerfile scaffolding and image build operations +- Kubernetes manifest generation and apply/delete operations +- Helm chart scaffolding +- Deployment status/log/history/rollback flows +- Environment profile management +- Data transformation utilities (YAML, JSON, TOML, XML, ENV, Base64) +- Template generation (for example GitHub Actions and Argo app templates) + +The goal is to reduce command sprawl and boilerplate when moving from code to deployable workloads. + +## How It Is Built + +The project is implemented in Go and organized as a Cobra-based CLI. + +High-level build path: +- `main.go` is the executable entry point. +- `cmd/` contains CLI command definitions and flag wiring. +- `pkg/` contains implementation logic used by commands. + +Build commands: + +```bash +go build -o codewise-cli main.go +# or +make build +``` + +Test commands: + +```bash +make test +go test ./... -v +``` + +## Runtime Connectivity And Control Flow + +The internal execution flow is: + +1. User runs a CLI command (for example `codewise k8s apply`). +2. Cobra command in `cmd/` parses args and flags. +3. Command handler calls a domain package in `pkg/`. +4. Domain package reads files/config and performs requested action. +5. For deployment workflows, external CLIs/services are invoked where needed. +6. Result is printed to terminal and process exits with success or error code. + +Conceptual connectivity map: + +```text +Terminal User + -> codewise (binary) + -> cmd/* (Cobra command layer) + -> pkg/* (business logic) + -> Local Filesystem (templates, manifests, config) + -> External Tools (docker, kubectl, helm) + -> Kubernetes API (through kubectl/helm operations) +``` + +## Project Structure And Responsibilities + +- `cmd/`: Command definitions, flags, argument validation, command wiring. +- `pkg/config/`: Configuration load/save defaults. +- `pkg/docker/`: Dockerfile init, validation, image build helpers. +- `pkg/k8s/`: Manifest generation, apply/delete orchestration. +- `pkg/helm/`: Helm chart scaffold generation. +- `pkg/deploy/`: Deploy planning, execution, logs, status, history, rollback. +- `pkg/env/`: Environment create/list/delete behaviors. +- `pkg/encoder/`: Format conversion and Base64 utilities. +- `pkg/generator/`: Project and template generation logic. +- `templates/`: Template source files used by template commands. +- `k8s/` and `helm/`: Generated scaffold outputs. +- `tests/` and `testdata/`: Test cases and fixture inputs/outputs. + +## Tech Stack + +Primary: +- Go 1.20 +- Cobra CLI framework (`github.com/spf13/cobra`) +- YAML support (`gopkg.in/yaml.v3`) +- TOML support (`github.com/BurntSushi/toml`) +- XML mapping support (`github.com/clbanning/mxj/v2`) +- Interactive prompts (`github.com/AlecAivazis/survey/v2`) + +Tooling and ecosystem dependencies: +- Docker CLI and daemon for image-related workflows +- kubectl and Kubernetes cluster context for K8s apply/delete workflows +- Helm CLI for chart-related workflows + +## How Commands Connect To Domains + +- `config` commands map to config domain for defaults and view/init operations. +- `docker` commands map to Docker domain for init/validate/build. +- `k8s` commands map to K8s domain for scaffold/apply/delete. +- `helm` commands map to Helm domain for scaffold init. +- `deploy` commands map to deployment domain for run/plan/status/logs/history/rollback. +- `env` commands map to environment domain for profile lifecycle. +- `encode` maps to transformation domain for file format conversions. +- `template` maps to generator/template domain for predefined scaffold files. + +## Development And Contribution Model + +Typical change flow: + +1. Add or update command wiring under `cmd/`. +2. Implement core logic in `pkg/`. +3. Add or update tests under `tests/` with fixtures in `testdata/`. +4. Validate with `go test ./... -v`. +5. Build with `make build` and run manual smoke commands. + +This layering keeps CLI surface concerns separate from business logic and improves testability. diff --git a/README.md b/README.md index 4ad8107..04de079 100644 --- a/README.md +++ b/README.md @@ -32,18 +32,20 @@ Clone the repository: ```bash git clone https://github.com/aryansharma9917/codewise-cli.git cd codewise-cli -```` +``` Build from source: ```bash -go build -o codewise main.go +make build +# or +go build -o codewise-cli main.go ``` (Optional) install globally: ```bash -sudo mv codewise /usr/local/bin/ +sudo mv codewise-cli /usr/local/bin/codewise ``` --- @@ -56,6 +58,21 @@ General syntax: codewise [subcommand] [flags] ``` +Local development usage (without global install): + +```bash +./codewise-cli [subcommand] [flags] +# or +go run . [subcommand] [flags] +``` + +--- + +## Documentation + +- [Testing runbook](TESTING_RUNBOOK.md) for copy-paste test and smoke commands +- [Project overview](PROJECT_OVERVIEW.md) for architecture, connectivity, build flow, and tech stack + --- ## Configuration @@ -201,9 +218,11 @@ codewise helm init . ├── cmd/ # CLI commands ├── pkg/ # Core logic (docker, k8s, helm, config, encode) +├── templates/ # Source templates used by generators ├── helm/ # Generated Helm charts ├── k8s/ # Generated Kubernetes manifests -├── config/ # Configuration helpers +├── tests/ # Automated tests +├── testdata/ # Fixtures used by tests and conversion checks ├── Dockerfile ├── go.mod └── main.go diff --git a/TESTING_RUNBOOK.md b/TESTING_RUNBOOK.md new file mode 100644 index 0000000..2f66d9d --- /dev/null +++ b/TESTING_RUNBOOK.md @@ -0,0 +1,178 @@ +# Codewise CLI Testing Runbook + +This runbook is designed for direct copy-paste testing from project root. + +## 1) Prerequisites + +Use these checks to confirm required tooling is available before running any workflow. + +```bash +go version +docker --version +kubectl version --client +helm version +``` + +## 2) Build And Baseline Validation + +Build the binary, then verify command wiring and version output. + +```bash +make clean +make build +./codewise-cli --help +./codewise-cli version +go run . --help +go run . version +``` + +## 3) Automated Tests + +Run the existing test suites first, then optional race and coverage checks. + +```bash +make test +go test ./... -v +go test ./... -race +go test ./... -coverprofile=coverage.out +go tool cover -func=coverage.out +``` + +## 4) Top-Level Command Surface Check + +These commands confirm every top-level command is registered and callable. + +```bash +./codewise-cli config --help +./codewise-cli deploy --help +./codewise-cli docker --help +./codewise-cli encode --help +./codewise-cli env --help +./codewise-cli helm --help +./codewise-cli init --help +./codewise-cli k8s --help +./codewise-cli template --help +``` + +## 5) Config Workflow + +This validates local configuration initialization and read-back. + +```bash +./codewise-cli config init +./codewise-cli config view +cat ~/.codewise/config.yaml +``` + +## 6) Encode/Convert Workflow (Fixture-Based) + +These commands validate common encode paths using files in `testdata/`. + +```bash +./codewise-cli encode -i testdata/sample.yaml -o /tmp/cw_sample_1.json +./codewise-cli encode -i testdata/sample.json -o /tmp/cw_sample_2.yaml --json-to-yaml +./codewise-cli encode -i testdata/sample.env -o /tmp/cw_sample_3.json --env-to-json +./codewise-cli encode -i testdata/sample.txt -o /tmp/cw_sample_4.b64 --base64 +./codewise-cli encode -i /tmp/cw_sample_4.b64 -o /tmp/cw_sample_5.txt --base64 --decode +``` + +Quick output validation for generated artifacts. + +```bash +ls -lh /tmp/cw_sample_1.json /tmp/cw_sample_2.yaml /tmp/cw_sample_3.json /tmp/cw_sample_4.b64 /tmp/cw_sample_5.txt +diff -u testdata/sample.txt /tmp/cw_sample_5.txt +``` + +## 7) Scaffold Generation (Local Safe) + +Use this to validate project scaffold generation for Kubernetes and Helm. + +```bash +rm -rf helm/chart k8s/app +./codewise-cli helm init +./codewise-cli k8s init +find helm -maxdepth 4 -type f | sort +find k8s -maxdepth 4 -type f | sort +``` + +## 8) Template Commands + +These validate template generation commands. + +```bash +./codewise-cli template github-action +./codewise-cli template argo-app +``` + +## 9) Docker Workflow (Requires Docker Daemon) + +Run these if Docker is available and running on your machine. + +```bash +./codewise-cli docker init +./codewise-cli docker validate +./codewise-cli docker build +docker images | grep -i codewise +``` + +## 10) Kubernetes Workflow (Dry-Run First) + +Use dry-run for safe validation without applying to the cluster. + +```bash +./codewise-cli k8s apply --dry-run +./codewise-cli k8s delete --dry-run +``` + +## 11) Kubernetes Real Apply (Only On Test Cluster) + +Run this section only when your kube context points to a non-production cluster. + +```bash +kubectl config current-context +./codewise-cli k8s apply --namespace dev +./codewise-cli deploy status --namespace dev +./codewise-cli deploy logs --namespace dev +./codewise-cli deploy history --namespace dev +./codewise-cli deploy rollback --namespace dev +./codewise-cli k8s delete --namespace dev +``` + +## 12) Environment Command Validation + +Use help checks and simple actions to validate env command behavior. + +```bash +./codewise-cli env --help +./codewise-cli env list +./codewise-cli env create dev +./codewise-cli env list +./codewise-cli env delete dev +./codewise-cli env list +``` + +## 13) Negative Testing + +These commands validate error handling and message quality for invalid inputs. + +```bash +./codewise-cli encode -i does-not-exist.yaml -o /tmp/out.json +./codewise-cli k8s apply --context definitely-not-real --dry-run +./codewise-cli deploy status --namespace does-not-exist +``` + +## 14) One-Line Regression Pack + +Use this compact command for quick regression checks before pushing changes. + +```bash +make build && go test ./... -v && ./codewise-cli encode -i testdata/sample.yaml -o /tmp/reg.json && ./codewise-cli helm init && ./codewise-cli k8s init && ./codewise-cli k8s apply --dry-run +``` + +## Expected Success Signals + +- Build exits with code 0. +- Test commands pass with code 0. +- Encode commands generate output files and decode roundtrip matches input. +- Helm and Kubernetes scaffold files are generated without runtime errors. +- Dry-run commands do not mutate cluster resources and still validate command flow. diff --git a/cmd/deploy.go b/cmd/deploy.go index 6a9e541..a8c57df 100644 --- a/cmd/deploy.go +++ b/cmd/deploy.go @@ -1,7 +1,6 @@ package cmd import ( - "github.com/aryansharma9917/codewise-cli/pkg/deploy" "github.com/spf13/cobra" ) diff --git a/cmd/docker.go b/cmd/docker.go index e8089ee..ed51528 100644 --- a/cmd/docker.go +++ b/cmd/docker.go @@ -1,7 +1,6 @@ package cmd import ( - "github.com/aryansharma9917/codewise-cli/pkg/docker" "github.com/spf13/cobra" ) diff --git a/cmd/env_list.go b/cmd/env_list.go index 49b38d3..74cba22 100644 --- a/cmd/env_list.go +++ b/cmd/env_list.go @@ -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", -RunE: func(cmd *cobra.Command, args []string) error { -envs, err := env.ListEnvs() -if err != nil { -return LogError(err.Error()) -} + 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 nil -} + 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) -} -return nil -}, + 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) } diff --git a/cmd/k8s_apply.go b/cmd/k8s_apply.go index 5a64dcf..a142580 100644 --- a/cmd/k8s_apply.go +++ b/cmd/k8s_apply.go @@ -1,7 +1,6 @@ package cmd import ( - "github.com/aryansharma9917/codewise-cli/pkg/k8s" "github.com/spf13/cobra" ) diff --git a/cmd/k8s_delete.go b/cmd/k8s_delete.go index d42545f..650c192 100644 --- a/cmd/k8s_delete.go +++ b/cmd/k8s_delete.go @@ -1,7 +1,6 @@ package cmd import ( - "github.com/aryansharma9917/codewise-cli/pkg/k8s" "github.com/spf13/cobra" ) diff --git a/cmd/k8s_init.go b/cmd/k8s_init.go index e7c1530..51ba47d 100644 --- a/cmd/k8s_init.go +++ b/cmd/k8s_init.go @@ -1,7 +1,6 @@ package cmd import ( - "github.com/aryansharma9917/codewise-cli/pkg/k8s" "github.com/spf13/cobra" ) diff --git a/cmd/version.go b/cmd/version.go index 64e9271..21882c8 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -12,7 +12,7 @@ var ( ) const ( - CLI_VERSION = "1.7.0" + CLI_VERSION = "1.8.0" OWNER = "AryanSharma9917" REPO = "Codewise-CLI" ) diff --git a/doc.go b/doc.go new file mode 100644 index 0000000..0dbbf3f --- /dev/null +++ b/doc.go @@ -0,0 +1,9 @@ +// Package main contains the Codewise CLI executable entrypoint. +// +// Codewise provides a unified command-line interface for DevOps workflows, +// including Docker, Kubernetes, Helm, deployment orchestration, environment +// management, and format encoding utilities. +// +// This module is intended to be used as an application binary, not as a +// reusable Go library. +package main