Skip to content

CLI output and exit codes

The output formats and the exit codes of hakocms-cli. This page also collects the rules for using it from scripts and CI.

Option List Single item Use when
None (terminal) Table with headers field: value lines A person reads it
None (pipe, file) Tab-separated lines without headers field: value lines Reading with cut or awk
--json JSON array (formatted) JSON object Passing to other tools
--jq <expression> Result of the expression Result of the expression Extracting only the values you need

An example of a list printed to a terminal:

ID STATUS UPDATED AT CREATED AT
pgxjuopeye1p published 2026-10-23T04:18:29.693Z 2026-10-23T04:18:29.693Z
iazte4ghzm55 draft 2026-10-23T04:18:29.640Z 2026-10-23T04:18:29.640Z

When passed to a pipe, there are no headers, and the columns are separated by tabs.

pgxjuopeye1p published 2026-10-23T04:18:29.693Z 2026-10-23T04:18:29.693Z
iazte4ghzm55 draft 2026-10-23T04:18:29.640Z 2026-10-23T04:18:29.640Z
  • If the environment variable NO_COLOR is set, no color is used
  • Dates and times are output in RFC 3339 in UTC (2026-10-23T04:18:29.693Z)

Outputs the Admin API response as it is. The meaning of each item is the same as in the Admin API reference.

  • A list is output as the array of contents, without the page wrapper (totalCount and so on). It has the same shape when you go through all pages with --all
  • New items that hakocms-cli does not know about are also output as they are

Filters JSON with a jq expression. The expression is applied to the JSON even without --json. You do not need to install jq separately.

Result of the expression Output
String As is, on one line, without quotes
Number, boolean, null As JSON, on one line
Object, array As formatted JSON, on several lines
Several results (.[]) Each result in turn, in the formats above
ターミナルウィンドウ
hakocms-cli entries list -t posts --jq '.[].id' # One ID per line
hakocms-cli entries list -t posts --all --jq 'length' # Count
hakocms-cli entries list -t posts --jq '.[] | {id, status} | tojson' # One JSON object per line
What is output Where
Results (table, JSON, result of the jq expression) Standard output
Progress (uploaded 1/2: …, apply …: queued), warnings, errors Standard error

With --json or --jq, errors are output to standard error as JSON.

{"error":{"status":404,"message":"not found"}}

status is the HTTP status from the Admin API. The meaning of each reason is in the Errors.

Flag Contents
(none) 30 items
--limit <n> n items
--all Everything, going through all pages

Some lists, such as exports, return up to 20 items, newest first.

Before an operation that cannot be undone, such as a deletion, the CLI asks whether to continue.

Weight Example In a terminal Outside a terminal (pipe, CI)
Light Saving and publishing entries Does not ask Does not ask
Medium Deleting entries, media, or webhooks; revoking API keys; applying a schema Asks with [y/N] Requires --force
Heavy Deleting spaces, content types, or users; anonymizing users Makes you type the target’s name (slug, content type ID, or user ID) Requires --confirm <name> (--force is not enough)

Confirmation messages include the destination name and the space.

  • With --no-input, the CLI asks nothing. If it needs to ask, it ends with an error

  • Outside a terminal, without --force or --confirm, the CLI shows the following and ends without doing anything

    error: `entries delete pgxjuopeye1p` needs --force when it cannot ask (not a terminal, or --no-input)

Exports, imports, and schema applies run as jobs inside Hako CMS. With --wait, the CLI checks every 2 seconds until the job finishes, then outputs the result.

export k4uexuzi2q9f: queued
export k4uexuzi2q9f: succeeded

If the job fails, the CLI ends with exit code 1.

Code Meaning Example
0 Success
1 Error API error (404, 400, and so on), network failure, answering “no” to a confirmation, job failure
2 Usage error Misspelled flag, missing required argument, unreadable JSON, unknown destination name
4 Login required No destination is set; the token is missing, expired, or revoked

In scripts, you can branch on the exit code.

ターミナルウィンドウ
hakocms-cli entries get <entry ID> -t posts --json > entry.json
case $? in
0) echo "取り出しました" ;;
4) echo "ログインし直してください" >&2; exit 1 ;;
*) echo "取り出せませんでした" >&2; exit 1 ;;
esac
ターミナルウィンドウ
hakocms-cli version
hakocms-cli 0.1.8 (Admin API 1)

This shows the version of hakocms-cli and the major version of the Admin API it uses. If the major version of the Hako CMS Admin API differs, every command shows a warning. In that case, update hakocms-cli (Install the CLI).