Skip to content

Commit 664ab81

Browse files
yuukiclaude
andcommitted
refactor: replace cobra subcommands with pflag/viper flags
Replace cobra CLI framework with pflag and viper to use simple flags (-c for client mode, -s for server mode) instead of subcommands. This simplifies the command-line interface and removes the dependency on cobra while maintaining all existing functionality. Changes: - Remove connect.go and serve.go subcommand files - Consolidate all CLI logic into main.go with pflag - Use -c/--client and -s/--server flags for mode selection - Update tests to work with new flag-based interface - Remove cobra dependency, keep pflag and viper - Update documentation to reflect new architecture 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 59bb183 commit 664ab81

17 files changed

+529
-417
lines changed

CLAUDE.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ go test ./...
2525

2626
## Development Workflow with GitHub
2727

28-
1. Create a new branch for [feature/bug-name] from main branch.
28+
1. Create a new branch for [feature/bug/refactor-name] from main branch.
2929
2. Coding the feature/bug.
3030
3. Add or fix tests.
3131
4. Check the code quality with testing, linting and formatting.
@@ -37,9 +37,7 @@ go test ./...
3737

3838
The project follows a simple flat structure with all Go files in the top-level directory:
3939

40-
- `main.go`: Entry point defining root Cobra command
41-
- `serve.go`: Server subcommand implementation
42-
- `connect.go`: Client subcommand implementation
40+
- `main.go`: Entry point with flag-based CLI using pflag and viper (-c for client, -s for server)
4341
- `server.go`: TCP/UDP server logic with context-based cancellation and errgroup for concurrent handling
4442
- `client.go`: Client implementation with persistent/ephemeral connection modes, rate limiting, and latency measurements
4543
- `option.go`: Default socket option implementations (non-Linux platforms)
@@ -79,7 +77,8 @@ The project includes test files (connect_test.go, serve_test.go, e2e_test.go). W
7977
## Dependencies
8078

8179
Key dependencies include:
82-
- github.com/spf13/cobra: CLI framework
80+
- github.com/spf13/pflag: POSIX-style command-line flag parsing
81+
- github.com/spf13/viper: Configuration management with flag binding
8382
- github.com/rcrowley/go-metrics: Performance metrics
8483
- go.uber.org/ratelimit: Rate limiting
8584
- golang.org/x/sync/errgroup: Concurrent error handling

client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ type JSONLinesResult struct {
361361
func printJSONLinesReport(w io.Writer, addrs []string, mergeResultsEachHost bool) {
362362
timestamp := time.Now().UTC().Format(time.RFC3339)
363363
results := []JSONLinesResult{}
364-
364+
365365
if mergeResultsEachHost {
366366
ts := getOrRegisterTimer("total.latency", "", mergeResultsEachHost)
367367
results = append(results, JSONLinesResult{
@@ -393,7 +393,7 @@ func printJSONLinesReport(w io.Writer, addrs []string, mergeResultsEachHost bool
393393
})
394394
}
395395
}
396-
396+
397397
for _, result := range results {
398398
if err := json.NewEncoder(w).Encode(result); err != nil {
399399
slog.Error("Failed to encode JSON result", "error", err)
@@ -412,4 +412,4 @@ func printReport(w io.Writer, addrs []string, mergeResultsEachHost bool) {
412412
ts := getOrRegisterTimer("total.latency", addr, mergeResultsEachHost)
413413
printStatLine(w, addr, ts)
414414
}
415-
}
415+
}

connect.go

Lines changed: 0 additions & 182 deletions
This file was deleted.

0 commit comments

Comments
 (0)