CLI's completion should know what options you've typed
4 months ago
- #Git
- #TypeScript
- #CLI
- Git's -C option allows context-aware completion, showing branch names from a specified repository path.
- Most CLI parsers treat options in isolation, leading to either useless completions or no completions for dependent options.
- Optique 0.10.0 introduces a dependency system to solve this problem while maintaining type safety.
- Static dependencies can be handled using the `or()` combinator, ensuring valid combinations are known at definition time.
- Runtime dependencies are addressed with `dependency()` and `derive()`, allowing valid values to depend on runtime input.
- The `@optique/git` package provides async value parsers for repository-aware completion, such as branch names from a specified Git repository.
- Multiple dependencies can be managed using `deriveFrom()`, which handles values from several options.
- Async support is available for I/O operations like reading from Git repositories or querying APIs.
- Optique's dependency system ensures type safety and catches invalid combinations at compile time.
- Optique 0.10.0 is available for pre-release testing via Deno or npm.