This guide is for future agents and maintainers working in this repository. It summarizes how the CLI is organized, how changes should be made, and which checks matter before handing work back.
table-printer-cli is the command-line interface for console-table-printer. It publishes a ctp binary that accepts JSON row data from an input argument or stdin, optionally accepts table options as JSON, and prints a formatted table using the console-table-printer library.
The companion repositories are usually checked out next to this repo:
../console-table-printer: the underlying rendering library and source of truth for table options.../console-table-docu: the Docusaurus documentation site, including CLI docs.
index.ts: CLI entry point and exportedrunCLIfunction. It configures Commander, reads package version metadata, handles--input,--stdin, and--tableOptions, and invokes the service.src/service.ts: parses and validates input/options, creates aTable, adds rows, and prints the table.src/inputVerifier.ts: JSON validation helpers for row input and table options.test/readmeExamples/: tests that exercise README-level examples.test/infrastructuralTests/: Jest discovery anddistpackage-shape tests.index.test.ts: CLI option handling tests with Commander and service mocks.src/*.test.ts: focused unit tests for validation and service behavior.static-resources/: README screenshots..github/workflows/: CI coverage and semantic-release workflows.PULL_REQUEST_TEMPLATE.md: PR template used by maintainers.
Use Yarn for this repository.
yarn
yarn build
yarn test
yarn lint
yarn formatUseful targeted checks:
yarn jest --config jestconfig.json index.test.ts
yarn jest --config jestconfig.json src/service.test.ts
yarn jest --config jestconfig.json test/readmeExamples
yarn jest --config jestconfig.json test/infrastructuralTests/jest-discovery.test.ts
yarn jest --config jestconfig.json test/infrastructuralTests/dist-contents.test.ts
npm packNotes:
yarn buildrunstscand emits CommonJS JavaScript plus.d.tsfiles intodist/.- The published binary is
ctp, mapped inpackage.jsontodist/index.js. yarn testusesjestconfig.jsonand enforces global 80% coverage thresholds.- CI runs on Node 24 with
yarn install --frozen-lockfile. package.jsonhas asetupscript that runsnpm install, but normal repo work and CI use Yarn.
The high-level flow is:
index.tscreates a Commander program inrunCLI.--inputpasses the input string directly toprintTableFromInp.--stdinreads file descriptor0, converts it to a string, and passes that toprintTableFromInp.--tableOptionsis passed as a raw JSON string.src/service.tsvalidates both JSON strings, parses them, constructsnew Table(options), adds each row, and callstable.printTable().
Important behavior:
- Input must be a JSON array. Non-array JSON is rejected.
- Empty arrays are valid and still print an empty table.
tableOptionsonly needs to be valid JSON; option semantics come fromconsole-table-printer.- The CLI entry point reads package version from
package.json, first from the parent ofdistfor installed usage and then from the current directory for development. runCLIis exported so tests can call CLI behavior without spawning a process.- The shebang in
index.tsis required for the installedctpbinary.
When adding or changing CLI behavior:
- Update Commander options in
index.ts. - Keep parsing/validation behavior in
src/inputVerifier.tsorsrc/service.ts. - Keep
console-table-printerrendering behavior in the library repo. Do not reimplement table formatting here. - Preserve
runCLI(argv = process.argv)so tests and embedders can pass explicit arguments. - Update README usage and screenshots when user-facing CLI behavior changes.
- Update docs in
../console-table-docu, especiallydocs/doc-cli-install-quick-start.mdanddocs/doc-cli-brew.md, when CLI flags, examples, install steps, or behavior change. - Check
../console-table-printerwhen adding or documenting table options, because the CLI forwards those options directly tonew Table(options).
Prefer keeping the CLI thin. Its job is to collect input, validate JSON, pass options through, and delegate rendering to the library.
Choose tests based on the change:
- CLI flags or argument routing: update
index.test.ts. - Input validation: update
src/inputVerifier.test.ts. - Table construction or option pass-through: update
src/service.test.ts. - README examples: update tests under
test/readmeExamples/. - Test discovery changes: update
test/infrastructuralTests/jest-discovery.test.tswhenever adding, removing, or renaming test files. - Build output or package-shape changes: update
test/infrastructuralTests/dist-contents.test.tsand runnpm packif package contents are affected.
When adding a test file, add its path to the explicit expectedFiles list in test/infrastructuralTests/jest-discovery.test.ts.
Useful flow for CLI changes:
yarn build
yarn jest --config jestconfig.json index.test.ts src/service.test.ts src/inputVerifier.test.ts
yarn jest --config jestconfig.json test/infrastructuralTestsThis repo has two documentation surfaces:
README.md: npm/GitHub quick start and core CLI examples.../console-table-docu: deployed docs site for users.
When CLI behavior changes, update both if users need to discover the new behavior. Keep option names, help output, screenshots, and examples consistent across README, docs, tests, and the Commander configuration.
For visual changes, update screenshots in this repo's static-resources/ and any corresponding docs-site images under ../console-table-docu/static/img/examples/.
- TypeScript is strict:
strict,strictNullChecks, andnoImplicitAnyare enabled. - Keep CLI logic small and explicit. Avoid hidden global state outside package-version detection.
- Preserve stdout/stderr intent in tests when changing error messages.
- Prefer readable fixture data in examples and tests. JSON should be compact enough for CLI usage but still obvious to reviewers.
- Do not add dependencies unless they are clearly justified; this package should stay lightweight.
The package publishes only dist through the files field, excluding test artifacts. Standard metadata such as package.json, README.md, and LICENSE are included by npm.
Package-sensitive fields:
main:dist/index.jstypes:dist/index.d.tsbin.ctp:dist/index.jsfiles:distwith test exclusions
Releases are handled by semantic-release on main and master. The release workflow builds the package and publishes through npm provenance.
- Forgetting the shebang in
index.tscan break the installed binary. - Changing CLI option names requires updates in README, docs, tests, and help output expectations.
tableOptionsis JSON passed through toconsole-table-printer; validate syntax here, but document semantics from the library.fs.readFileSync(0)is how stdin is read. Keep this behavior testable.- Adding tests without updating the Jest discovery expected list will fail infrastructure tests.
- Package-shape changes can pass source tests while breaking npm consumers.
For documentation-only changes, inspect the Markdown and update docs-site references when applicable.
For code changes, usually run:
yarn build
yarn test
yarn lintFor package-shape or binary-entry changes, also run:
npm packIf tests are not run, say so in the handoff and identify the highest-risk unchecked area.