Designing a Command for Other Programs to Use
A reusable command states how it reads data, what its success output contains, and how failures reach a caller.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Choose a small interface
A quantity summary can accept a path or standard input with a declared encoding, emit one structured record, and report invalid fields separately. Command streams describe where outputs belong.
Test a composed use
Feed one program's result into another that implements the promised consumer contract. Also exercise malformed data and a retryable I/O failure. Integration tests verify behavior once both tools are connected.[1]
Build one stable transformation around stdin and stdout
A utility consuming one text ID per line can emit normalized IDs in the same order. It can also expose a file option while sharing the same parser. Keeping progress separate lets the output be piped into another command. See text input from the standard stream.
Input IDs: "A7", "B2"
Data output: "a7", "b2" if case folding is the stated policy
Errors or progress follow a separate channel
Decide how to handle one invalid item in a batch
The command may fail immediately or continue with a reported rejection. That choice affects partial outputs and how callers use the status. Test an ordinary pipeline and an invalid item following valid output.