diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..286cee2 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,40 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "CLI", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}", + "console": "integratedTerminal", + "env": { + "GO_ENV": "development", + "WILD_CENTRAL_ENV": "development" + }, + "args": ["--help"], + "cwd": "${workspaceFolder}" + }, + { + "name": "CLI with args", + "type": "go", + "request": "launch", + "mode": "debug", + "program": "${workspaceFolder}", + "console": "integratedTerminal", + "env": { + "GO_ENV": "development", + "WILD_CENTRAL_ENV": "development" + }, + "args": "${input:cliArgs}", + "cwd": "${workspaceFolder}" + } + ], + "inputs": [ + { + "id": "cliArgs", + "type": "promptString", + "description": "CLI arguments (e.g., 'list instances' or 'create --name test')" + } + ] +} diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d6a6895 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,23 @@ +{ + "go.gopath": "", + "go.goroot": "", + "go.useLanguageServer": true, + + "gopls": { + "experimentalWorkspaceModule": true, + "build.experimentalWorkspaceModule": true + }, + + "go.lintTool": "golangci-lint", + "go.lintOnSave": "workspace", + "go.formatTool": "goimports", + "go.testOnSave": false, + + "[go]": { + "editor.formatOnSave": true, + "editor.codeActionsOnSave": { + "source.organizeImports": "explicit" + }, + "editor.suggest.snippetsPreventQuickSuggestions": false + } +} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..365e94f --- /dev/null +++ b/Makefile @@ -0,0 +1,77 @@ +.PHONY: help build dev test clean install lint fmt vet man + +# Binary name +BINARY_NAME=wild +BUILD_DIR=build + +# Go parameters +GOCMD=go +GOBUILD=$(GOCMD) build +GOCLEAN=$(GOCMD) clean +GOTEST=$(GOCMD) test +GOGET=$(GOCMD) get +GOMOD=$(GOCMD) mod +GOFMT=$(GOCMD) fmt +GOVET=$(GOCMD) vet + +# Build flags +LDFLAGS=-ldflags "-s -w" + +help: ## Show this help message + @echo 'Usage: make [target]' + @echo '' + @echo 'Available targets:' + @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " %-15s %s\n", $$1, $$2}' $(MAKEFILE_LIST) + +build: ## Build the CLI binary + @echo "Building $(BINARY_NAME)..." + @mkdir -p $(BUILD_DIR) + $(GOBUILD) $(LDFLAGS) -o $(BUILD_DIR)/$(BINARY_NAME) . + +dev: build ## Build and run the CLI with --help + @echo "Running $(BINARY_NAME)..." + ./$(BUILD_DIR)/$(BINARY_NAME) --help + +test: ## Run tests + @echo "Running tests..." + $(GOTEST) -v ./... + +test-cover: ## Run tests with coverage + @echo "Running tests with coverage..." + $(GOTEST) -v -coverprofile=coverage.out ./... + $(GOCMD) tool cover -html=coverage.out -o coverage.html + @echo "Coverage report generated: coverage.html" + +clean: ## Clean build artifacts + @echo "Cleaning..." + $(GOCLEAN) + @rm -rf $(BUILD_DIR) + @rm -f coverage.out coverage.html + +install: build ## Install the binary to $(go env GOPATH)/bin + @echo "Installing $(BINARY_NAME)..." + @mkdir -p $$($(GOCMD) env GOPATH)/bin + @cp $(BUILD_DIR)/$(BINARY_NAME) $$($(GOCMD) env GOPATH)/bin/ + +deps: ## Download dependencies + @echo "Downloading dependencies..." + $(GOMOD) download + $(GOMOD) tidy + +fmt: ## Format Go code + @echo "Formatting code..." + $(GOFMT) ./... + +vet: ## Run go vet + @echo "Running go vet..." + $(GOVET) ./... + +lint: fmt vet ## Run formatters and linters + +check: lint test ## Run all checks (lint + test) + +man: ## Generate man page + @echo "Generating man page..." + @./install-man-page.sh + +all: clean lint test build ## Clean, lint, test, and build diff --git a/cmd/app.go b/cmd/app.go index f9f97cb..29b02ce 100644 --- a/cmd/app.go +++ b/cmd/app.go @@ -183,4 +183,3 @@ func init() { appCmd.AddCommand(appDeleteCmd) appCmd.AddCommand(appStatusCmd) } - diff --git a/cmd/backup.go b/cmd/backup.go index 6406626..091dc3d 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -52,4 +52,3 @@ var restoreCmd = &cobra.Command{ return nil }, } - diff --git a/cmd/cluster.go b/cmd/cluster.go index 4fa999c..fb697fd 100644 --- a/cmd/cluster.go +++ b/cmd/cluster.go @@ -281,4 +281,3 @@ func init() { clusterKubeconfigCmd.Flags().Bool("persist", false, "Save kubeconfig to instance directory") clusterKubeconfigCmd.Flags().Bool("generate", false, "Regenerate kubeconfig from the cluster") } - diff --git a/cmd/instance.go b/cmd/instance.go index b7e4a8e..857c710 100644 --- a/cmd/instance.go +++ b/cmd/instance.go @@ -162,7 +162,7 @@ var instanceDeleteCmd = &cobra.Command{ var instanceCurrentCmd = &cobra.Command{ Use: "current", Short: "Show current instance", - Long: `Display the instance that would be used by commands. + Long: `Display the instance that would be used by commands. Resolution order: 1. --instance flag diff --git a/cmd/node.go b/cmd/node.go index c3542a0..8f98afc 100644 --- a/cmd/node.go +++ b/cmd/node.go @@ -479,4 +479,3 @@ func init() { nodeUpdateCmd.Flags().Bool("maintenance", false, "Set maintenance mode") nodeUpdateCmd.Flags().Bool("no-maintenance", false, "Clear maintenance mode") } - diff --git a/cmd/pxe.go b/cmd/pxe.go index a47644a..a3de007 100644 --- a/cmd/pxe.go +++ b/cmd/pxe.go @@ -75,4 +75,3 @@ func init() { pxeCmd.AddCommand(pxeListCmd) pxeCmd.AddCommand(pxeDownloadCmd) } - diff --git a/cmd/service.go b/cmd/service.go index 49b4dfe..12a19e7 100644 --- a/cmd/service.go +++ b/cmd/service.go @@ -322,4 +322,3 @@ func init() { serviceCmd.AddCommand(serviceListCmd) serviceCmd.AddCommand(serviceInstallCmd) } - diff --git a/cmd/utility.go b/cmd/utility.go index ab4f47e..e643a1d 100644 --- a/cmd/utility.go +++ b/cmd/utility.go @@ -65,4 +65,3 @@ var nodeIPCmd = &cobra.Command{ return nil }, } - diff --git a/internal/prompt/example_test.go b/internal/prompt/example_test.go deleted file mode 100644 index 93ebe5f..0000000 --- a/internal/prompt/example_test.go +++ /dev/null @@ -1,73 +0,0 @@ -package prompt_test - -import ( - "fmt" - // "github.com/wild-cloud/wild-central/wild/internal/prompt" -) - -// ExampleString demonstrates the String prompt function -func ExampleString() { - // This example shows the prompt output format - // Actual usage would read from stdin interactively - fmt.Println("Enter SMTP host [smtp.gmail.com]:") - // User input: (returns default) - // Result: "smtp.gmail.com" - - fmt.Println("Enter SMTP host [smtp.gmail.com]:") - // User input: "smtp.example.com" - // Result: "smtp.example.com" -} - -// ExampleInt demonstrates the Int prompt function -func ExampleInt() { - // This example shows the prompt output format - fmt.Println("Enter SMTP port [587]:") - // User input: (returns default) - // Result: 587 - - fmt.Println("Enter SMTP port [587]:") - // User input: "465" - // Result: 465 -} - -// ExampleBool demonstrates the Bool prompt function -func ExampleBool() { - // This example shows the prompt output format - fmt.Println("Enable TLS [Y/n]:") - // User input: (returns default true) - // Result: true - - fmt.Println("Enable TLS [Y/n]:") - // User input: "n" - // Result: false - - fmt.Println("Enable debug mode [y/N]:") - // User input: (returns default false) - // Result: false - - fmt.Println("Enable debug mode [y/N]:") - // User input: "yes" - // Result: true -} - -// Example usage in a real command -func ExampleUsage() { - // Example of using prompt functions in a CLI command: - // - // host, err := prompt.String("Enter SMTP host", "smtp.gmail.com") - // if err != nil { - // return err - // } - // - // port, err := prompt.Int("Enter SMTP port", 587) - // if err != nil { - // return err - // } - // - // useTLS, err := prompt.Bool("Enable TLS", true) - // if err != nil { - // return err - // } - // - // fmt.Printf("Configuration: host=%s, port=%d, tls=%v\n", host, port, useTLS) -}