Skip to content

Commit edef1f3

Browse files
yeldarbyclaude
andcommitted
docs: update CLAUDE.md, CLI-COMMANDS.md, CONTRIBUTING.md for modular CLI
- CLAUDE.md: Replace old CLI section with full modular architecture docs (package structure, handler pattern, agent experience requirements, documentation policy) - CLI-COMMANDS.md: Rewrite as concise quickstart linking to docs.roboflow.com for full reference. Covers install, global flags, common examples, --json for agents, resource shorthand, backwards compat table. - CONTRIBUTING.md: Add CLI Development section with handler template, agent experience checklist, and documentation policy. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 71c530d commit edef1f3

File tree

3 files changed

+164
-272
lines changed

3 files changed

+164
-272
lines changed

CLAUDE.md

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,26 +84,49 @@ The Roboflow Python SDK follows a hierarchical object model that mirrors the Rob
8484
- **rfapi** (`roboflow/adapters/rfapi.py`) - Low-level API communication
8585
- **deploymentapi** (`roboflow/adapters/deploymentapi.py`) - Model deployment operations
8686

87-
### CLI Interface
88-
89-
The `roboflow` command line tool (`roboflow/roboflowpy.py`) provides:
90-
- Authentication: `roboflow login`
91-
- Dataset operations: `roboflow download`, `roboflow upload`, `roboflow import`
92-
- Inference: `roboflow infer`
93-
- Project/workspace management: `roboflow project`, `roboflow workspace`
87+
### CLI Package (`roboflow/cli/`)
88+
89+
The CLI is a modular package with auto-discovered handler modules. `roboflow/roboflowpy.py` is a backwards-compatibility shim that delegates to `roboflow.cli.main`.
90+
91+
**Package structure:**
92+
- `__init__.py` — Root parser with global flags (`--json`, `--workspace`, `--api-key`, `--quiet`), auto-discovery via `pkgutil.iter_modules`, custom `_CleanHelpFormatter`, and `_reorder_argv` for flexible flag positioning
93+
- `_output.py``output(args, data, text)` for JSON/text output, `output_error(args, msg, hint, exit_code)` for structured errors, `suppress_sdk_output()` to silence SDK noise, `stub()` for unimplemented commands
94+
- `_table.py``format_table(rows, columns)` for columnar list output
95+
- `_resolver.py``resolve_resource(shorthand)` for parsing `project`, `ws/project`, `ws/project/3`
96+
- `handlers/` — One file per command group (auto-discovered). `_aliases.py` registers backwards-compat top-level commands (loaded last)
97+
98+
**Adding a new command:**
99+
1. Create `roboflow/cli/handlers/mycommand.py`
100+
2. Export `register(subparsers)` — it will be auto-discovered
101+
3. Use lazy imports for heavy dependencies (inside handler functions, not at module top level)
102+
4. Use `output()` for all output, `output_error()` for all errors
103+
5. Wrap SDK calls in `with suppress_sdk_output():` to prevent "loading..." noise
104+
6. Add tests in `tests/cli/test_mycommand_handler.py`
105+
106+
**Agent experience requirements for all CLI commands:**
107+
- Support `--json` for structured output (stable schema)
108+
- No interactive prompts when all required flags are provided
109+
- Structured error output: `{"error": {"message": "...", "hint": "..."}}` on stderr
110+
- Exit codes: 0 = success, 1 = error, 2 = auth error, 3 = not found
111+
- Actionable error messages: always tell the user what went wrong AND what to do
112+
113+
**Documentation policy:** `CLI-COMMANDS.md` in this repo is a quickstart only. The full command reference lives in `roboflow-product-docs` (published to docs.roboflow.com). When adding commands, update both.
94114

95115
### Key Design Patterns
96116

97117
1. **Hierarchical Access**: Always access objects through their parent (Workspace → Project → Version → Model)
98118
2. **API Key Flow**: API key is passed down through the object hierarchy
99119
3. **Format Flexibility**: Supports multiple dataset formats (YOLO, COCO, Pascal VOC, etc.)
100120
4. **Batch Operations**: Upload and download operations support concurrent processing
121+
5. **CLI Noun-Verb Pattern**: Commands follow `roboflow <noun> <verb>` (e.g. `roboflow project list`). Common operations have top-level aliases (`login`, `upload`, `download`)
122+
6. **CLI Auto-Discovery**: Handler modules in `roboflow/cli/handlers/` are loaded automatically — no registration list to maintain
123+
7. **Backwards Compatibility**: Legacy command names and flag signatures are preserved as hidden aliases
101124

102125
## Project Configuration
103126

104127
- **Python Version**: 3.8+
105128
- **Main Dependencies**: See `requirements.txt`
106-
- **Entry Point**: `roboflow=roboflow.roboflowpy:main`
129+
- **Entry Point**: `roboflow=roboflow.roboflowpy:main` (shim delegates to `roboflow.cli.main`)
107130
- **Code Style**: Enforced by ruff with Google docstring convention
108131
- **Type Checking**: mypy configured for Python 3.8
109132

0 commit comments

Comments
 (0)