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: 5 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: '1.25'
cache: true

- name: Run go fmt
Expand Down Expand Up @@ -50,17 +50,11 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: '1.25'
cache: true

- name: Run tests
run: go test -v -race -coverprofile=coverage.out ./...

- name: Upload coverage
uses: codecov/codecov-action@v4
with:
files: ./coverage.out
fail_ci_if_error: false
run: go test -v ./...

build:
name: Build
Expand All @@ -79,7 +73,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '1.24'
go-version: '1.25'
cache: true

- name: Build binary
Expand All @@ -90,7 +84,7 @@ jobs:
go build -v -o forkspacer-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.goos == 'windows' && '.exe' || '' }} .

- name: Verify binary
if: matrix.goos == 'linux'
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
run: |
chmod +x forkspacer-${{ matrix.goos }}-${{ matrix.goarch }}
./forkspacer-${{ matrix.goos }}-${{ matrix.goarch }} version
73 changes: 73 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
.PHONY: build build-all test lint clean install fmt tidy help

# Binary name
BINARY_NAME=forkspacer

# Build variables
VERSION?=dev
GIT_COMMIT=$(shell git rev-parse --short HEAD 2>/dev/null || echo "none")
BUILD_DATE=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
LDFLAGS=-ldflags "-X github.com/forkspacer/cli/cmd.version=$(VERSION) -X github.com/forkspacer/cli/cmd.gitCommit=$(GIT_COMMIT) -X github.com/forkspacer/cli/cmd.buildDate=$(BUILD_DATE)"

# Go parameters
GOCMD=go
GOBUILD=$(GOCMD) build
GOTEST=$(GOCMD) test
GOVET=$(GOCMD) vet
GOFMT=$(GOCMD) fmt
GOMOD=$(GOCMD) mod

help: ## Show this help
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'

build: ## Build binary for current platform
$(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME) .

build-all: ## Build for all platforms
@echo "Building for multiple platforms..."
GOOS=darwin GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-darwin-arm64 .
GOOS=darwin GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-darwin-amd64 .
GOOS=linux GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-amd64 .
GOOS=linux GOARCH=arm64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-linux-arm64 .
GOOS=windows GOARCH=amd64 $(GOBUILD) $(LDFLAGS) -o $(BINARY_NAME)-windows-amd64.exe .
@echo "Build complete!"

test: ## Run tests
$(GOTEST) -v ./...

lint: ## Run linters
@echo "Running go vet..."
@$(GOVET) ./...
@echo "Checking formatting..."
@if [ -n "$$(gofmt -s -l .)" ]; then \
echo "Code is not formatted. Run 'make fmt'"; \
gofmt -s -l .; \
exit 1; \
fi
@echo "Linting passed!"

fmt: ## Format code
$(GOFMT) ./...

tidy: ## Tidy go.mod
$(GOMOD) tidy

install: build ## Install binary to /usr/local/bin
@echo "Installing $(BINARY_NAME) to /usr/local/bin..."
sudo mv $(BINARY_NAME) /usr/local/bin/
@echo "Installed successfully!"

clean: ## Clean build artifacts
@echo "Cleaning build artifacts..."
@rm -f $(BINARY_NAME)*
@rm -f coverage.out
@echo "Clean complete!"

run: build ## Build and run version command
./$(BINARY_NAME) version

verify: lint test build ## Run all verification steps
@echo "All verification steps passed!"

.DEFAULT_GOAL := help
32 changes: 26 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ The CLI provides direct Kubernetes integration, beautiful terminal output, and f
- 🎨 **Beautiful Output** - Styled terminal output with colors, spinners, and progress indicators
- ⚡ **Fast Validation** - Client-side validation for instant feedback
- 🚀 **Easy to Use** - Intuitive commands that feel natural
- 🔧 **Direct K8s Access** - No API server required, uses your kubeconfig
- 🔧 **Shared Business Logic** - Uses Forkspacer API server library for consistent operations
- 🌍 **Cross-Platform** - Works on macOS, Linux, and Windows
- 📝 **Shell Completion** - Tab completion for bash, zsh, fish, and powershell
- 🔄 **Workspace Lifecycle** - Create, hibernate, wake, and manage workspaces
Expand Down Expand Up @@ -382,7 +382,7 @@ kubectl config get-contexts

### Prerequisites

- Go 1.24 or later
- Go 1.25 or later
- Kubernetes cluster for testing
- [Forkspacer Operator](https://github.com/forkspacer/forkspacer) installed

Expand Down Expand Up @@ -418,15 +418,35 @@ cli/
│ ├── hibernate.go
│ └── wake.go
├── pkg/ # Shared packages
│ ├── k8s/ # Kubernetes client wrapper
│ ├── printer/ # Output formatting
│ ├── styles/ # Terminal styling
│ └── validation/ # Input validation
│ ├── workspace/ # Workspace service wrapper (delegates to api-server)
│ ├── printer/ # Output formatting (tables, spinners)
│ ├── styles/ # Terminal styling (colors, layouts)
│ └── validation/ # Input validation (DNS, cron)
├── .github/ # GitHub workflows & templates
├── scripts/ # Install scripts
└── main.go # Entry point
```

### Architecture

The CLI imports the Forkspacer API server's service layer as a library, providing a unified approach to workspace operations:

```
api-server/pkg/services/forkspacer (shared business logic)
↓ ↓
HTTP Handlers CLI Wrapper Service
(for REST API) (pkg/workspace/)
CLI Commands
```

**Benefits:**
- Single source of truth for business logic
- Type-safe compile-time checking
- No network overhead for CLI operations
- Consistent validation and error handling
- Shared code maintenance between API and CLI

### Testing

```bash
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/forkspacer/cli/pkg/styles"
"github.com/spf13/cobra"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"runtime"

"github.com/spf13/cobra"
"github.com/forkspacer/cli/pkg/styles"
"github.com/spf13/cobra"
)

var (
Expand Down
Loading
Loading