Skip to content

Commit 81c23ed

Browse files
committed
docs: rewrite AGENTS.md with corrected paths, consolidated customization guide, and maintenance workflow
Fixes incorrect test name (TestServices -> TestService), adds full file paths to the customization reference table, documents both customization map key formats, removes duplicated sections, and includes a Dependabot update workflow with verified commands. Assisted-by: Crush:glm-5.2
1 parent d3d9ece commit 81c23ed

1 file changed

Lines changed: 131 additions & 22 deletions

File tree

AGENTS.md

Lines changed: 131 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,26 @@ This repository is a **shell completion provider for AWS CLI**. It uses [carapac
1515

1616
```
1717
cmd/
18-
carapace-aws/ # Main completion binary
18+
carapace-aws/ # Main completion binary
1919
cmd/
20-
root.go # CLI structure: root + service + operation commands
21-
botocore/ # ~280 YAML files (aws.<service>.yaml)
22-
botocore.go # Loads embedded YAML files
23-
botocore_generated.go # Service name description map
24-
aws.<service>.yaml # Per-service command specs
20+
root.go # CLI structure: root + service + operation commands
21+
botocore/ # ~280 YAML files (aws.<service>.yaml)
22+
botocore.go # Loads embedded YAML files
23+
botocore_generated.go # Service name -> description map
24+
aws.<service>.yaml # Per-service command specs
2525
common/
26-
bridge.go # Delegates to carapace-bridge AWS completer
26+
bridge.go # Delegates to carapace-bridge AWS completer
2727
generate/
28-
main.go # Orchestrates spec regeneration
29-
carapace-spec-botocore/ # Spec generator binary
28+
main.go # Orchestrates spec regeneration
29+
carapace-spec-botocore/ # Spec generator binary
3030
cmd/
31-
root.go # Parses botocore data → YAML
32-
customizations/ # ~40 service-specific customization files
33-
customizations.go
31+
root.go # Parses botocore data -> YAML
32+
argumentRenames.go # Flag name normalization map
33+
customizations/ # ~40 service-specific customization files
34+
customizations.go # Registers customization functions
35+
removals.go # Commands to skip (deprecated/removed)
3436
s3.go, ecs.go, iam.go, etc.
35-
pkg/actions/aws/ # Go completion actions (profile, region)
37+
pkg/actions/aws/ # Go completion actions (profile, region)
3638
```
3739

3840
### Key Dependencies
@@ -55,7 +57,7 @@ ls cmd/ | xargs -I'{}' sh -c "cd ./cmd/{} && go build -v ."
5557
```bash
5658
go test -v -coverprofile=profile.cov ./...
5759
# Integration tests (requires AWS credentials):
58-
go test -C cmd/carapace-aws -tags integration -run TestServices -c .
60+
go test -C cmd/carapace-aws -tags integration -run TestService -c .
5961
```
6062

6163
### Lint/Format
@@ -87,11 +89,6 @@ goreleaser release --clean # Triggered by git tags
8789
4. Customizations modify specs (add/remove commands, flags, descriptions)
8890
5. `botocore_generated.go` is regenerated with service map
8991

90-
**Adding a new customization:**
91-
- Create `cmd/carapace-spec-botocore/cmd/customizations/<service>.go`
92-
- Register a function in `init()` that modifies the command spec
93-
- Add to the customizations map: `customizations["servicename"] = func(cmd *command.Command) error { ... }`
94-
9592
## Spec Format
9693

9794
AWS command specs are YAML files following this schema:
@@ -113,9 +110,58 @@ Flag conventions:
113110
- `--flag=` = optional flag
114111
- `nargs: -1` = variadic (multiple values allowed)
115112

113+
## Customizations
114+
115+
Customizations are service-specific modifications applied to the generated specs (add/remove flags, rename commands, etc.). They live in `cmd/carapace-spec-botocore/cmd/customizations/` and are registered in a shared `customizations` map via `init()` functions.
116+
117+
### Customization Map Keys
118+
119+
The map supports two key formats:
120+
121+
- **`"servicename"`** - applies to all operations within a service (e.g. `"s3"`, `"ec2"`)
122+
- **`"servicename.operation-name"`** - applies to a specific operation (e.g. `"ec2.run-instances"`, `"iam.create-virtual-mfa-device"`)
123+
124+
### Adding a New Service Customization
125+
126+
1. Create `cmd/carapace-spec-botocore/cmd/customizations/<service>.go`
127+
2. Add an `init()` function that registers into the `customizations` map
128+
3. Use the appropriate key format:
129+
```go
130+
// Service-level (all operations)
131+
customizations["myservice"] = func(cmd *command.Command) error { ... }
132+
133+
// Operation-level (specific command)
134+
customizations["myservice.some-operation"] = func(cmd *command.Command) error { ... }
135+
```
136+
137+
### Customization File Reference
138+
139+
| File | Location | Purpose |
140+
|------|----------|---------|
141+
| `customizations.go` | `cmd/carapace-spec-botocore/cmd/customizations/` | Registers customization functions, defines the shared `customizations` map |
142+
| `removals.go` | `cmd/carapace-spec-botocore/cmd/customizations/` | Commands to skip (deprecated/removed) |
143+
| `<service>.go` | `cmd/carapace-spec-botocore/cmd/customizations/` | Service-specific flag/command fixes |
144+
| `argumentRenames.go` | `cmd/carapace-spec-botocore/cmd/` | Flag name normalization (e.g. `--version` -> `--api-version`); follows AWS CLI's [argrename.py](https://github.com/aws/aws-cli/blob/develop/awscli/customizations/argrename.py) patterns |
145+
146+
### Example: Adding a Missing Flag
147+
148+
```go
149+
func init() {
150+
customizations["ec2.some-command"] = func(cmd *command.Command) error {
151+
delete(cmd.Flags, "--old-flag")
152+
cmd.AddFlag(command.Flag{
153+
Longhand: "--new-flag",
154+
Description: "Description here",
155+
Value: true,
156+
})
157+
return nil
158+
}
159+
}
160+
```
161+
116162
## Gotchas
117163

118-
1. **CamelCase kebab-case**: The generator has a `CamelCaseToDash()` function with extensive hardcoded fixes for edge cases (e.g., `ec2-instance-id`, `whats-app` `whatsapp`).
164+
1. **CamelCase -> kebab-case**: The generator has a `CamelCaseToDash()` function with extensive hardcoded fixes for edge cases (e.g. `ec2-instance-id`, `whats-app` -> `whatsapp`).
119165

120166
2. **S3 is special**: S3 commands are named `s3api` not `s3`. The `s3.go` customization renames the spec.
121167

@@ -127,10 +173,73 @@ Flag conventions:
127173

128174
6. **pflag replacement**: The `replace github.com/spf13/pflag => github.com/carapace-sh/carapace-pflag v1.1.0` directive in `go.mod` ensures carapace's patched pflag is used.
129175

130-
7. **Gorealeaser hooks**: Runs `go generate` before build (`before.hooks`).
176+
7. **Goreleaser hooks**: Runs `go generate` before build (`before.hooks`).
131177

132178
## Testing Approach
133179

134180
- Unit tests for Go code
135181
- Integration tests require AWS credentials (`-tags integration`)
136-
- CI runs full test suite + staticcheck + formatting check
182+
- CI runs full test suite + staticcheck + formatting check
183+
184+
## Maintenance Workflow (Dependabot Updates)
185+
186+
When AWS CLI updates the botocore definitions, follow this workflow:
187+
188+
### Prerequisites
189+
- AWS credentials configured (for integration tests)
190+
- GitHub CLI authenticated
191+
192+
### Step 1: Run the Generator
193+
```bash
194+
# Clones aws/aws-cli at version in package.json, generates YAML specs
195+
go generate ./...
196+
```
197+
198+
### Step 2: Run Tests to Identify Breaking Changes
199+
```bash
200+
# Full build and test
201+
go build -C cmd/carapace-aws -v .
202+
go test -C cmd/carapace-aws -tags integration -run TestService -c .
203+
204+
# Test all operations for a single service (example: ec2)
205+
SERVICE=ec2 ./cmd/carapace-aws/carapace-aws.test
206+
```
207+
208+
The test uses `carapace.DiffPatch()` to compare AWS CLI completions vs carapace completions:
209+
- **Red lines (`-`)**: carapace-aws is missing completions that AWS CLI provides
210+
- **Green lines (`+`)**: carapace-aws has extra completions that AWS CLI doesn't have
211+
212+
Red lines indicate problems that need fixing. Green lines are usually informational.
213+
214+
### Step 3: Analyze and Fix the Changes
215+
216+
Reference: [AWS CLI Command Reference](https://docs.aws.amazon.com/cli/latest/reference/)
217+
218+
Common issues and fixes:
219+
220+
#### A. New command needs flag renames
221+
Fix in `cmd/carapace-spec-botocore/cmd/argumentRenames.go`
222+
223+
#### B. Service has renamed commands
224+
Add to `cmd/carapace-spec-botocore/cmd/customizations/removals.go` to skip, or update the relevant `<service>.go` customization file.
225+
226+
#### C. New flags on existing command
227+
Update `cmd/carapace-spec-botocore/cmd/customizations/<service>.go` (see the [Example: Adding a Missing Flag](#example-adding-a-missing-flag) section above).
228+
229+
#### D. CamelCase -> kebab-case edge cases
230+
Update `CamelCaseToDash()` in `cmd/carapace-spec-botocore/cmd/root.go`
231+
232+
#### E. Service structure changes
233+
Create/update `cmd/carapace-spec-botocore/cmd/customizations/<service>.go`
234+
235+
### Step 4: Test the Fix
236+
```bash
237+
SERVICE=ec2 ./cmd/carapace-aws/carapace-aws.test
238+
```
239+
240+
### Step 5: Format and Commit
241+
```bash
242+
go fmt ./...
243+
git add -A
244+
git commit -m "fix: adapt to AWS CLI botocore changes"
245+
```

0 commit comments

Comments
 (0)