Scripting with the CLI
Use the Corfedo CLI in scripts and CI with JSON output, request files, paging limits, exit codes and API keys.
Scripts and pipelines sign in with an API key file, read JSON output and act on exit codes.
Run in CI with an API key
- Create an API key with only the repositories the pipeline needs.
- Store the key file as a CI secret and write it to a file only the job's user can read.
- Configure a profile and run commands with it:
corfedo auth configure-api-key --key-file "$RUNNER_TEMP/corfedo.key.json" --profile ci
corfedo search --profile ci --query '"TODO(security)"' --format jsonOnly auth login opens a browser. In unattended runs, --non-interactive makes it fail at once with interaction_required.
Output formats
| Option | Output |
|---|---|
--format text | The default. Readable output for a terminal |
--format json | One JSON envelope per command |
--format jsonl | One JSON record per page, then a summary record. Required with --all |
The JSON envelope:
{
"schemaVersion": "1",
"command": "search",
"outcome": "complete",
"data": { },
"pagination": { "continuation": null, "exhausted": true, "stoppedByClientLimit": false },
"error": null,
"warnings": []
}outcome is, for example, complete, partial, not_found, stale, unavailable or error. On failure, error.code names the reason. Usage messages and text errors go to stderr.
Read every page
--all reads every page of a listing command. It needs --format jsonl:
corfedo search --query '"RetryPolicy"' --all --format jsonl --max-pages 20 --max-output-bytes 8388608--max-pages (default 20) and --max-output-bytes (default 8 MiB) stop the stream early with the outcome partial and exit 7. The final summary record holds the last continuation, so a request file can continue from there. Without a summary record the output is incomplete.
Requests from a file
Read commands also accept the complete API request as JSON with --request FILE, or --request - for standard input. It replaces the command's arguments and can carry a continuation from an earlier page.
echo '{"prefix": "acme/", "target": "repositories"}' | corfedo scope lookup --request -
echo '{"field": "symbol", "prefix": "Retry"}' | corfedo completions --request -corfedo schema --command NAME lists a command's request fields.
Exit codes
Act on the exit code: 0 is a complete result, 7 a partial one, and other codes name the kind of failure. --allow-partial turns 7 into 0. CLI commands lists every code, and Ask from the CLI the codes of ask.
Related
- CLI commands lists every command and option.
- API reference describes every request field.