Skip to content

Commit 1ca36f3

Browse files
authored
clarify the need for cross-platform (#197)
1 parent f46e7ff commit 1ca36f3

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

.agents/skills/add-command-spec/SKILL.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,42 @@ description: Guide for adding new command completion specs to warp-command-signa
1010
1. **Create JSON spec**: `command-signatures/json/<command>.json` following the [Fig completion spec schema](https://fig.io/docs/reference)
1111
2. **Create generator** (if needed): Add `command-signatures/src/generators/<command>.rs`, define a `generator()` function returning `CommandSignatureGenerators`, and register it in `generators/mod.rs`
1212

13+
## Platform Compatibility
14+
15+
When implementing generator commands, ensure they work across all applicable platforms where the command exists. For example, a UNIX-only command should work on both macOS and Linux, not just the platform being used for development.
16+
17+
### Common pitfalls
18+
19+
- Commands that work differently across platforms (for example, user lookup via `dscl` on macOS vs `getent` on Linux)
20+
- Commands with different output formats across platforms
21+
- Hardcoded paths that differ between systems
22+
23+
### Solutions
24+
25+
Identify which platforms the command needs to support.
26+
27+
Prioritize approaches in this order:
28+
29+
1. **Use cross-platform commands** when available — commands that work identically on the relevant platforms minimize maintenance burden. However, this is not always possible.
30+
2. **Feature detection** — prefer testing for command availability or flag support over platform checks:
31+
- `command -v <cmd>` to check if a tool exists, see `fn users_generator()` in `command-signatures/src/generators/common.rs` for an example.
32+
- `<cmd> --version 2>/dev/null` or `<cmd> --help` to test flag support
33+
3. **Graceful fallbacks** — when a platform-specific tool is unavailable, fall back to portable alternatives (e.g., `getent``dscl``/etc/passwd`).
34+
4. **Platform detection as last resort** — only use `uname` or similar if the above approaches are insufficient.
35+
36+
Implement platform-specific logic in the generator only when behavior fundamentally differs across systems.
37+
38+
## Generator Reusability
39+
40+
Generators that are shared by multiple commands should live in `command-signatures/src/generators/common.rs`. Before implementing a new generator:
41+
42+
1. Search the codebase to see if a similar generator has already been implemented by another command.
43+
2. If one exists and can be reused, use it directly.
44+
3. If a generator is used across multiple commands, move it to `common.rs` for reuse.
45+
4. Generators that are only used by a single command should remain in their own module (e.g., `command-signatures/src/generators/<command>.rs`).
46+
47+
See `fn users_generator()` in `common.rs` as an example of a cross-platform generator used by multiple commands.
48+
1349
## Style Guideline
1450

1551
Match the formatting conventions used in the command's `--help` output. For example, if the help text uses `UPPER_CASE` for positional argument names, use the same casing in the spec's argument `name` field.

0 commit comments

Comments
 (0)