Skip to content

Commit c1f4dc1

Browse files
authored
chore(snip): clarify help text to describe both remove and filter modes (#192)
1 parent e089c60 commit c1f4dc1

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ The CLI provides four main command groups:
131131
- `localize` - Localize an OpenAPI specification by copying external references to a target directory
132132
- `optimize` - Optimize an OpenAPI specification by deduplicating inline schemas
133133
- `sanitize` - Remove unwanted elements from an OpenAPI specification
134-
- `snip` - Remove selected operations from an OpenAPI specification (interactive or CLI)
134+
- `snip` - Remove or filter operations in an OpenAPI specification (interactive or CLI)
135135
- `upgrade` - Upgrade an OpenAPI specification to the latest supported version
136136
- `validate` - Validate an OpenAPI specification document
137137
- `query` - Query an OpenAPI specification using the [oq pipeline language](./oq/README.md) to answer structural and semantic questions about schemas and operations

cmd/openapi/commands/openapi/README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ What the explorer provides:
10781078

10791079
### `snip`
10801080

1081-
Remove selected operations from an OpenAPI specification and automatically clean up unused components.
1081+
Remove or filter operations in an OpenAPI specification and automatically clean up unused components.
10821082

10831083
```bash
10841084
# Interactive mode - browse and select operations via TUI
@@ -1100,6 +1100,12 @@ openapi spec snip --operation /users/{id}:DELETE,/admin:GET ./spec.yaml
11001100
# CLI mode - mixed approaches
11011101
openapi spec snip --operationId deleteUser --operation /admin:GET ./spec.yaml
11021102
1103+
# CLI mode - filter to only specific operations (remove everything else)
1104+
openapi spec snip --keepOperationId getUser --keepOperationId listUsers ./spec.yaml
1105+
1106+
# CLI mode - filter by path:method
1107+
openapi spec snip --keepOperation /users:GET,/users/{id}:GET ./spec.yaml
1108+
11031109
# Write in-place (CLI mode only)
11041110
openapi spec snip -w --operation /internal/debug:GET ./spec.yaml
11051111
```
@@ -1116,10 +1122,10 @@ openapi spec snip -w --operation /internal/debug:GET ./spec.yaml
11161122

11171123
**Command-Line Mode** (operation flags specified):
11181124

1119-
- Remove operations specified via flags without UI
1120-
- Supports `--operationId` for operation IDs
1121-
- Supports `--operation` for path:method pairs
1122-
- Both flags support comma-separated values or multiple flags
1125+
- **Remove mode** (`--operationId`, `--operation`): remove the specified operations
1126+
- **Filter mode** (`--keepOperationId`, `--keepOperation`): filter the spec down to only the specified operations, removing everything else
1127+
- Remove and filter flags cannot be combined
1128+
- All flags support comma-separated values or multiple flags
11231129

11241130
**What snip does:**
11251131

cmd/openapi/commands/openapi/snip.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ var (
2424

2525
var snipCmd = &cobra.Command{
2626
Use: "snip <input-file> [output-file]",
27-
Short: "Remove operations from an OpenAPI specification",
28-
Long: `Remove selected operations from an OpenAPI specification and clean up unused components.
27+
Short: "Remove or filter operations in an OpenAPI specification",
28+
Long: `Remove or filter operations in an OpenAPI specification and clean up unused components.
2929
3030
Stdin is supported in CLI mode — either pipe data directly or use '-' explicitly:
3131
cat spec.yaml | openapi spec snip --operationId deleteUser
@@ -37,12 +37,16 @@ This command can operate in two modes:
3737
Launch a terminal UI to browse and select operations for removal.
3838
- Navigate with j/k or arrow keys
3939
- Press Space to select/deselect operations
40-
- Press 'a' to select all, 'A' to deselect all
40+
- Press 'a' to select all, 'A' to deselect all
4141
- Press 'w' to write the result
4242
- Press 'q' or Esc to cancel
4343
44-
2. Command-Line Mode (--operationId or --operation flags):
45-
Remove operations specified via flags without launching the UI.
44+
2. Command-Line Mode (flags specified):
45+
Remove or filter operations specified via flags without launching the UI.
46+
- Remove mode (--operationId, --operation): remove the specified operations.
47+
- Filter mode (--keepOperationId, --keepOperation): filter the spec down to
48+
only the specified operations, removing everything else.
49+
Remove and filter flags cannot be combined.
4650
4751
Output options:
4852
- No output file: writes to stdout (pipe-friendly)
@@ -71,6 +75,12 @@ Examples:
7175
# CLI mode - mixed operation IDs and path:method
7276
openapi spec snip --operationId deleteUser --operation /admin:GET ./spec.yaml
7377
78+
# CLI mode - filter to only specific operations (remove everything else)
79+
openapi spec snip --keepOperationId getUser --keepOperationId listUsers ./spec.yaml
80+
81+
# CLI mode - filter by path:method
82+
openapi spec snip --keepOperation /users:GET,/users/{id}:GET ./spec.yaml
83+
7484
# CLI mode - write to stdout for piping
7585
openapi spec snip --operation /internal/debug:GET ./spec.yaml > ./public-spec.yaml`,
7686
Args: stdinOrFileArgs(1, 2),

0 commit comments

Comments
 (0)