Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Statscraft 0.61.0, release v0.61.0

命令行帮助

The output of statscraft --help and of --help on every subcommand. The command line explains them with examples.

Statistics workbench

Usage: statscraft <COMMAND>

Commands:
  describe  Show the dictionary and basic counts of a data file or of a session
  run       Run syntax. With --session the dataset, settings and macros are kept between runs
  chart     Add a chart given as JSON to the output: the chart --json writes, or a Vega-Lite specification of a simple view. Runs it as the syntax BEGIN CHART, a Statscraft extension
  check     Validate syntax without saving or writing anything; with --session, against its dataset
  export    Export the output of the running statscraft-gui window to a file, as its File > Export does: the tables and charts of its designated output window
  output    Show what an output window of the running statscraft-gui holds: every command and its tables and charts, which are hidden and which are selected
  undo      Take back the last run that changed the data in the running statscraft-gui window, as its Edit > Undo does; the output stays. Up to 10 runs go back, one per call
  redo      Do again the run that the last undo took back, as Edit > Redo does in the running statscraft-gui window; a new change after the undo ends the redo
  help      Show the syntax of a command, or list all commands
  plan      Lower bounded syntax to an OpenStatSpec transformation plan (JSON), or apply it in a database
  db        Store datasets in an OpenStatSpec database (SQLite, PostgreSQL, MySQL, MariaDB or Dolt) and read them back
  update    Update this installation to the latest published release; --check only checks for one
  mcp       Serve the tools of this program to an AI agent over MCP (standard input and output)
  code      Run a JavaScript async arrow function in code mode, as the MCP tool run_code does: every MCP tool is a function of the object statscraft, with the same arguments, the same default session and the same file sessions as `statscraft mcp`. Prints what the function returns as JSON; console.log lines go to standard error
  connect   Connect Statscraft's MCP server to the AI agents on this computer (Claude, ChatGPT and Codex, Cursor, Copilot, Gemini); --list only shows them, --remove takes it out again

Options:
  -h, --help     Print help
  -V, --version  Print version

statscraft describe

Show the dictionary and basic counts of a data file or of a session

Usage: statscraft describe [OPTIONS] [FILE]

Arguments:
  [FILE]  A .sav or .zsav file

Options:
  -s, --session <SESSION>  Describe this session (dataset, settings, macros) instead of a file; gui is the window
      --json               Print the result as JSON
  -h, --help               Print help

statscraft run

Run syntax. With --session the dataset, settings and macros are kept between runs

Usage: statscraft run [OPTIONS] [FILE]

Arguments:
  [FILE]  Syntax file, or - for standard input

Options:
  -e, --execute <TEXT>               Syntax text given directly
  -s, --session <SESSION>            Session name: the dataset, settings and macros are loaded from and saved to .statscraft/sessions/<name>. The name gui sends the syntax to the running statscraft-gui window instead
      --lines <FIRST-LAST>           Run only the commands inside this inclusive line range, for example 40-55
      --json                         Print tables, charts, changes, warnings and errors as JSON
      --vega-lite                    Also give every chart as a Vega-Lite specification: with --json as its member vega_lite, in Markdown as a code block after the chart's data table
      --encoding <NAME>              Encoding of the syntax file, such as windows-1257 or 1252. Default: UTF-8 when the file is valid UTF-8 (with or without a byte order mark), else the system's legacy code page
      --xlsx <FILE>                  Also write every table and chart of the run to this Excel workbook, one sheet per table; a chart as its data table with an editable chart beside it
      --xlsx-one-sheet               With --xlsx, put all tables on one sheet, one below the other
      --xlsx-no-titles               With --xlsx, leave out the title above each table and chart; labels, captions and what a plugin adds stay, and a sheet is still named after its table
      --plugin <PROGRAM>             With --xlsx, let this plugin program colour, comment and lay out the custom tables, with its settings from the active data's attributes (see docs/plugins.md). Give it more than once for several plugins: they run in that order, and where two style the same thing the later one wins
      --plugin-template <FILE>       With --plugin, a design template file (made by Export in the window's Plugin Settings, see docs/plugins.md): its settings win over the data's attributes, as an active template does in the window. One file per plugin, holding exactly one template of it
      --charts <DIR>                 Also write every chart of the run as a picture into this folder, made if missing: 01-<title>.svg, 02-<title>.svg and so on
      --chart-format <CHART_FORMAT>  With --charts, the picture format [default: svg] [possible values: svg, png]
  -h, --help                         Print help

statscraft chart

Add a chart given as JSON to the output: the chart --json writes, or a Vega-Lite specification of a simple view. Runs it as the syntax BEGIN CHART, a Statscraft extension

Usage: statscraft chart [OPTIONS] <FILE>

Arguments:
  <FILE>  The chart as a JSON file, or - for standard input

Options:
  -s, --session <SESSION>            Session name, as for run; gui adds the chart to the output of the running window
      --json                         Print the result as JSON
      --vega-lite                    Also give the chart as a Vega-Lite specification, as for run
      --xlsx <FILE>                  Also write every table and chart of the run to this Excel workbook, one sheet per table; a chart as its data table with an editable chart beside it
      --xlsx-one-sheet               With --xlsx, put all tables on one sheet, one below the other
      --xlsx-no-titles               With --xlsx, leave out the title above each table and chart; labels, captions and what a plugin adds stay, and a sheet is still named after its table
      --plugin <PROGRAM>             With --xlsx, let this plugin program colour, comment and lay out the custom tables, with its settings from the active data's attributes (see docs/plugins.md). Give it more than once for several plugins: they run in that order, and where two style the same thing the later one wins
      --plugin-template <FILE>       With --plugin, a design template file (made by Export in the window's Plugin Settings, see docs/plugins.md): its settings win over the data's attributes, as an active template does in the window. One file per plugin, holding exactly one template of it
      --charts <DIR>                 Also write every chart of the run as a picture into this folder, made if missing: 01-<title>.svg, 02-<title>.svg and so on
      --chart-format <CHART_FORMAT>  With --charts, the picture format [default: svg] [possible values: svg, png]
  -h, --help                         Print help

statscraft check

Validate syntax without saving or writing anything; with --session, against its dataset

Usage: statscraft check [OPTIONS] [FILE]

Arguments:
  [FILE]  Syntax file, or - for standard input

Options:
  -e, --execute <TEXT>      Syntax text given directly
  -s, --session <SESSION>   Session name: the dataset, settings and macros are loaded from and saved to .statscraft/sessions/<name>. The name gui sends the syntax to the running statscraft-gui window instead
      --lines <FIRST-LAST>  Run only the commands inside this inclusive line range, for example 40-55
      --json                Print tables, charts, changes, warnings and errors as JSON
      --vega-lite           Also give every chart as a Vega-Lite specification: with --json as its member vega_lite, in Markdown as a code block after the chart's data table
      --encoding <NAME>     Encoding of the syntax file, such as windows-1257 or 1252. Default: UTF-8 when the file is valid UTF-8 (with or without a byte order mark), else the system's legacy code page
  -h, --help                Print help

statscraft export

Export the output of the running statscraft-gui window to a file, as its File > Export does: the tables and charts of its designated output window

Usage: statscraft export [OPTIONS] <FILE>

Arguments:
  <FILE>  The file to write: .xlsx, .html or .pdf; a relative path starts in the current folder

Options:
      --format <FORMAT>  xlsx, html or pdf. Default: from the extension of the file
      --one-sheet        Excel: all tables on one sheet, one below the other, instead of one sheet per table
      --selected         Only the tables selected in the output window
      --hidden           Hidden items too
  -h, --help             Print help

statscraft output

Show what an output window of the running statscraft-gui holds: every command and its tables and charts, which are hidden and which are selected

Usage: statscraft output [OPTIONS]

Options:
      --document <DOCUMENT>  The output document; default: the designated output window
      --json                 Print the window's answer as JSON
  -h, --help                 Print help

statscraft undo

Take back the last run that changed the data in the running statscraft-gui window, as its Edit > Undo does; the output stays. Up to 10 runs go back, one per call

Usage: statscraft undo

Options:
  -h, --help  Print help

statscraft redo

Do again the run that the last undo took back, as Edit > Redo does in the running statscraft-gui window; a new change after the undo ends the redo

Usage: statscraft redo

Options:
  -h, --help  Print help

statscraft plan

Lower bounded syntax to an OpenStatSpec transformation plan (JSON), or apply it in a database

Usage: statscraft plan [OPTIONS] [FILE]

Arguments:
  [FILE]  Syntax file, or - for standard input

Options:
  -e, --execute <TEXT>            Syntax text given directly
      --input-schema <FILE>       Input schema: a JSON file with {"variables": [{"name", "storage_kind", ...}]}
  -s, --session <SESSION>         Take the input schema from the dataset of this session
      --sqlite <DB>               OpenStatSpec SQLite database file
      --postgres <URL>            PostgreSQL: postgres://user@host:port/database[?schema=NAME], schema default openstatspec; TLS with &sslmode=verify-full|verify-ca|require and &sslrootcert=CA.pem
      --mysql <URL>               MySQL or MariaDB: mysql://user@host:port/database, a database dedicated to the catalog; TLS with ?ssl-mode=VERIFY_IDENTITY|VERIFY_CA|REQUIRED and &ssl-ca=CA.pem
      --dolt <URL>                Dolt sql-server: mysql://user@host:port/database, a database dedicated to the catalog; TLS as for --mysql
      --name <DATASET>            Dataset name in the database
      --apply                     Apply the plan to the dataset in place
      --expected-branch <BRANCH>  Dolt: the branch the apply must run on
      --expected-head <COMMIT>    Dolt: the commit HEAD must be at
      --actor <ACTOR>             Who applies the plan, for the audit row; defaults to $USER
      --profile <PROFILE>         Frontend profile version [default: 0.3] [possible values: 0.1, 0.2, 0.3]
      --alias <ALIAS>             Symbolic name of the input dataset in the plan [default: input]
  -h, --help                      Print help

Prints one line of canonical JSON: {"ok":true,"plan":...,"plan_hash":...,"source_hash":...}, or {"ok":false,"error":{"code":...,"message":...,"line":...,"column":...},...}. The plan hash is SHA-256 of the canonical plan; the source hash is SHA-256 of the source with line ends converted to LF.

Profile 0.1: RECODE, VARIABLE LABELS, VALUE LABELS.
Profile 0.2 adds COMPUTE target = operand, IF (predicate) target = operand, FORMATS (F only), VARIABLE LEVEL and EXECUTE.
Profile 0.3 adds comments, TO lists, NE <> ~= and NOT, LOWEST/HIGHEST ranges and ADD VALUE LABELS.
Anything else is rejected: this is OpenStatSpec's bounded frontend, not the full language of `statscraft run`.

With --sqlite DB, --postgres URL, --mysql URL or --dolt URL and --name DATASET the input schema comes from that OpenStatSpec dataset, and --apply applies the plan to it in place, in one transaction with one audit row; the output then has "applied":{"apply_id":...,"dataset_id":...,"operation_count":...}. On Dolt, --apply needs --expected-branch and --expected-head: the session must be on that branch at that commit with a clean working set, and the changes stay uncommitted.

statscraft db

Store datasets in an OpenStatSpec database (SQLite, PostgreSQL, MySQL, MariaDB or Dolt) and read them back

Usage: statscraft db <COMMAND>

Commands:
  export        Store a .sav/.zsav file, or the dataset of a session, as a dataset in the database
  import        Read a dataset from the database into a .sav/.zsav file or a session
  capabilities  Print the adapter's capability declaration: versions, limits and atomicity per profile

Options:
  -h, --help  Print help

Prints one line of canonical JSON: {"ok":true,...} or {"ok":false,"error":{"code":...,"message":...}}.

The database is dedicated to OpenStatSpec: a SQLite file, a PostgreSQL schema, or a MySQL, MariaDB or Dolt database. On Dolt, `db export` leaves its changes in the working set and never commits, and `db import` writes nothing at all. Export creates the catalog in a new or empty one and refuses one holding anything else. Each dataset is one table data_<name> with __case_ordinal and one column per variable; the dictionary lives in the catalog tables. A URL without a password takes it from the STATSCRAFT_DB_PASSWORD environment variable; passwords are never printed. Connections are plain TCP unless the URL asks for TLS; TLS always verifies the server certificate against the CA file or the bundled Mozilla roots, and the host name unless the mode is verify-ca.

statscraft db export

Store a .sav/.zsav file, or the dataset of a session, as a dataset in the database

Usage: statscraft db export [OPTIONS] [FILE]

Arguments:
  [FILE]  A .sav or .zsav file

Options:
  -s, --session <SESSION>  Export the dataset of this session instead of a file
      --sqlite <DB>        OpenStatSpec SQLite database file
      --postgres <URL>     PostgreSQL: postgres://user@host:port/database[?schema=NAME], schema default openstatspec; TLS with &sslmode=verify-full|verify-ca|require and &sslrootcert=CA.pem
      --mysql <URL>        MySQL or MariaDB: mysql://user@host:port/database, a database dedicated to the catalog; TLS with ?ssl-mode=VERIFY_IDENTITY|VERIFY_CA|REQUIRED and &ssl-ca=CA.pem
      --dolt <URL>         Dolt sql-server: mysql://user@host:port/database, a database dedicated to the catalog; TLS as for --mysql
      --name <NAME>        Dataset name: ASCII letters, digits and _; defaults to the file or session name
  -h, --help               Print help

statscraft db import

Read a dataset from the database into a .sav/.zsav file or a session

Usage: statscraft db import [OPTIONS] --name <NAME>

Options:
      --sqlite <DB>        OpenStatSpec SQLite database file
      --postgres <URL>     PostgreSQL: postgres://user@host:port/database[?schema=NAME], schema default openstatspec; TLS with &sslmode=verify-full|verify-ca|require and &sslrootcert=CA.pem
      --mysql <URL>        MySQL or MariaDB: mysql://user@host:port/database, a database dedicated to the catalog; TLS with ?ssl-mode=VERIFY_IDENTITY|VERIFY_CA|REQUIRED and &ssl-ca=CA.pem
      --dolt <URL>         Dolt sql-server: mysql://user@host:port/database, a database dedicated to the catalog; TLS as for --mysql
      --name <NAME>        Dataset name
      --out <FILE>         Write this .sav or .zsav file
  -s, --session <SESSION>  Make the dataset the one of this session instead
      --allow-loss         Go on when the catalog holds items the dataset cannot keep, and record each loss
  -h, --help               Print help

statscraft db capabilities

Print the adapter's capability declaration: versions, limits and atomicity per profile

Usage: statscraft db capabilities

Options:
  -h, --help  Print help

statscraft update

Update this installation to the latest published release; --check only checks for one

Usage: statscraft update [OPTIONS]

Options:
      --check            Only check: exit code 0 when up to date, 10 when a newer release exists
      --json             With --check, print the result as JSON
      --plugin <PLUGIN>  With --check, check this plugin program for a newer version instead; it never installs one (the window's Edit > Settings > Plugins does that)
  -h, --help             Print help

statscraft mcp

Serve the tools of this program to an AI agent over MCP (standard input and output)

Usage: statscraft mcp

Options:
  -h, --help  Print help

statscraft code

Run a JavaScript async arrow function in code mode, as the MCP tool run_code does: every MCP tool is a function of the object statscraft, with the same arguments, the same default session and the same file sessions as `statscraft mcp`. Prints what the function returns as JSON; console.log lines go to standard error

Usage: statscraft code [OPTIONS] <FILE>

Arguments:
  <FILE>  The script file, or - for standard input

Options:
      --json  Print ok, value, logs and error as JSON instead of the value alone
  -h, --help  Print help

statscraft connect

Connect Statscraft's MCP server to the AI agents on this computer (Claude, ChatGPT and Codex, Cursor, Copilot, Gemini); --list only shows them, --remove takes it out again

Usage: statscraft connect [OPTIONS] [CLIENT]

Arguments:
  [CLIENT]  The agent: claude-desktop, claude-code, codex (also the Codex view of the ChatGPT app), cursor, copilot (VS Code), gemini or antigravity. On Windows, the agents inside WSL as --list names them, such as codex-wsl:Ubuntu. Default: every agent found on this computer

Options:
      --remove  Take Statscraft out of the agent's settings (every agent when none is named)
      --list    Only show which agents are installed and connected; change nothing
      --json    Print the result as JSON
  -h, --help    Print help