Skip to content

Commit 8d7e865

Browse files
committed
feat: add cobra framework with help, version commands
1 parent f291248 commit 8d7e865

File tree

14 files changed

+257
-20
lines changed

14 files changed

+257
-20
lines changed

.goreleaser.yml

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,24 @@ release:
8686
name_template: "{{ .ProjectName }} {{ .Tag }}"
8787

8888
header: |
89-
## AWS Local Sync {{ .Tag }}
90-
91-
High-performance CLI tool that syncs data from AWS services (RDS, DynamoDB, S3, Elasticsearch, etc.) to your local development environment.
92-
93-
### Highlights
89+
High-performance CLI tool that syncs data from AWS services to your local development environment.
9490
9591
footer: |
92+
## Installation
9693
97-
---
98-
99-
### Installation
100-
101-
#### Binary installation
94+
### Binary installation
10295
```bash
10396
# Download and extract (example for Linux x86_64)
10497
curl -sSL https://github.com/jakec-dev/aws-local-sync/releases/download/{{ .Tag }}/aws-local-sync_Linux_x86_64.tar.gz | tar xz
10598
106-
# Verify checksum signature
99+
#### Verify checksum signature
107100
cosign verify-blob \
108101
--certificate aws-local-sync_checksums.txt.pem \
109102
--signature aws-local-sync_checksums.txt.sig \
110103
aws-local-sync_checksums.txt
111104
```
112105
113-
#### Go installation
106+
### Go installation
114107
```bash
115108
go install github.com/jakec-dev/aws-local-sync/cmd/aws-local-sync@{{ .Tag }}
116109
```

.lefthook.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ pre-commit:
33
commands:
44
golangci-lint:
55
glob: "*.go"
6-
run: golangci-lint run --fix --fast-only {staged_files}
6+
run: golangci-lint run --fix --new-from-rev HEAD~1
77
stage_fixed: true
88
go-mod-tidy:
99
glob: "go.mod"

Makefile

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ GIT_COMMIT := $(shell git rev-parse --short HEAD)
1111
BUILD_TIME := $(shell date +%FT%T%z)
1212

1313
LDFLAGS := "-s -w \
14-
-X 'main.Version=$(VERSION)' \
15-
-X 'main.GitCommit=$(GIT_COMMIT)' \
16-
-X 'main.BuildTime=$(BUILD_TIME)'"
14+
-X 'github.com/jakec-dev/aws-local-sync/internal/version.version=$(VERSION)' \
15+
-X 'github.com/jakec-dev/aws-local-sync/internal/version.gitCommit=$(GIT_COMMIT)' \
16+
-X 'github.com/jakec-dev/aws-local-sync/internal/version.buildTime=$(BUILD_TIME)'"
1717

1818
GREEN := $(shell tput -Txterm setaf 2)
1919
YELLOW := $(shell tput -Txterm setaf 3)
@@ -76,6 +76,10 @@ install: ## Install all development dependencies, tools, and git hooks
7676
lint: ## Run code linters via golangci-lint
7777
golangci-lint run
7878

79+
.PHONY: lint-fix
80+
lint-fix: ## Fix linting and formatting issues
81+
golangci-lint run --fix
82+
7983
.PHONY: audit
8084
audit: test ## Run full audit: verify modules, scan for issues and vulnerabilities
8185
go mod tidy -diff

README.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Key features:
2222
go install github.com/jakec-dev/aws-local-sync/cmd/aws-local-sync@latest
2323

2424
# Then use it from anywhere:
25-
aws-local-sync
25+
aws-local-sync --help
2626
```
2727

2828
### Option 2: Run from source
@@ -33,10 +33,20 @@ git clone https://github.com/jakec-dev/aws-local-sync.git
3333
cd aws-local-sync
3434

3535
# Build the CLI
36-
go build -o bin/aws-local-sync ./cmd/aws-local-sync
36+
make build
3737

3838
# Run the CLI
39-
./bin/aws-local-sync
39+
./bin/aws-local-sync --help
40+
```
41+
42+
### Basic Usage
43+
44+
```sh
45+
# Show available commands
46+
aws-local-sync --help
47+
48+
# Check version and build info
49+
aws-local-sync version
4050
```
4151

4252
## Contributing

cmd/aws-local-sync/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package main
22

3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/jakec-dev/aws-local-sync/internal/cli"
8+
)
9+
310
func main() {
4-
// Placeholder
11+
if err := cli.Execute(cli.NewRootCommand()); err != nil {
12+
fmt.Fprintln(os.Stderr, err)
13+
os.Exit(1)
14+
}
515
}

go.mod

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
module github.com/jakec-dev/aws-local-sync
22

33
go 1.24.3
4+
5+
require github.com/spf13/cobra v1.9.1
6+
7+
require (
8+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
9+
github.com/spf13/pflag v1.0.6 // indirect
10+
)

go.sum

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
2+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
3+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
4+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
5+
github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo=
6+
github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0=
7+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
8+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
9+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
10+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

internal/cli/commands.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cli
2+
3+
import "github.com/spf13/cobra"
4+
5+
func RegisterCommands(rootCmd *cobra.Command) {
6+
rootCmd.AddCommand(NewVersionCommand(rootCmd.OutOrStdout()))
7+
}

internal/cli/commands_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package cli_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/jakec-dev/aws-local-sync/internal/cli"
9+
)
10+
11+
func TestAllCommandsPresent(t *testing.T) {
12+
cmd := &cobra.Command{Use: "test"}
13+
14+
cli.RegisterCommands(cmd)
15+
16+
expected := map[string]bool{"version": false}
17+
for _, sc := range cmd.Commands() {
18+
if _, ok := expected[sc.Name()]; ok {
19+
expected[sc.Name()] = true
20+
}
21+
}
22+
for name, seen := range expected {
23+
if !seen {
24+
t.Errorf("Expected subcommand %q to be registered", name)
25+
}
26+
}
27+
}

internal/cli/root.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
6+
"github.com/spf13/cobra"
7+
)
8+
9+
func NewRootCommand() *cobra.Command {
10+
cmd := &cobra.Command{
11+
Use: "aws-local-sync",
12+
Short: "Sync data from AWS services to your local development environment",
13+
Long: `aws-local-sync is a high-performance CLI tool for syncing data from AWS services
14+
into your local development environment.
15+
16+
Documentation:
17+
https://github.com/jakec-dev/aws-local-sync/wiki`,
18+
SilenceUsage: true,
19+
SilenceErrors: true,
20+
}
21+
22+
RegisterCommands(cmd)
23+
24+
return cmd
25+
}
26+
27+
func Execute(cmd *cobra.Command) error {
28+
if err := cmd.Execute(); err != nil {
29+
return fmt.Errorf("command execution failed: %w", err)
30+
}
31+
return nil
32+
}

0 commit comments

Comments
 (0)