Set up dev env.

This commit is contained in:
2025-10-11 21:42:33 +00:00
parent 24245e46e8
commit caabd298b3
12 changed files with 141 additions and 81 deletions

40
.vscode/launch.json vendored Normal file
View File

@@ -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')"
}
]
}

23
.vscode/settings.json vendored Normal file
View File

@@ -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
}
}

77
Makefile Normal file
View File

@@ -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

View File

@@ -183,4 +183,3 @@ func init() {
appCmd.AddCommand(appDeleteCmd)
appCmd.AddCommand(appStatusCmd)
}

View File

@@ -52,4 +52,3 @@ var restoreCmd = &cobra.Command{
return nil
},
}

View File

@@ -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")
}

View File

@@ -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

View File

@@ -479,4 +479,3 @@ func init() {
nodeUpdateCmd.Flags().Bool("maintenance", false, "Set maintenance mode")
nodeUpdateCmd.Flags().Bool("no-maintenance", false, "Clear maintenance mode")
}

View File

@@ -75,4 +75,3 @@ func init() {
pxeCmd.AddCommand(pxeListCmd)
pxeCmd.AddCommand(pxeDownloadCmd)
}

View File

@@ -322,4 +322,3 @@ func init() {
serviceCmd.AddCommand(serviceListCmd)
serviceCmd.AddCommand(serviceInstallCmd)
}

View File

@@ -65,4 +65,3 @@ var nodeIPCmd = &cobra.Command{
return nil
},
}

View File

@@ -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: <empty> (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: <empty> (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: <empty> (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: <empty> (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)
}