Skip to content

Scripting

The commands of twf are made to be used in scripts, like those of gh.

A command that prints a list looks where its output goes:

  • In a terminal it prints a table with a header, for people.
  • In a pipe or a file it prints tab-separated lines without a header, for a script.
Terminal window
vendor/bin/twf office list | cut -f1

twf process-xml does the same with XML: indented in a terminal, as Twinfield returned it in a pipe.

A list command takes --json for the same rows as JSON, for example for jq:

Terminal window
vendor/bin/twf office list --json | jq -r '.[] | select(.country == "NL") | .code'
Status Meaning
0 The command succeeded.
1 The command failed.

An error is one line on standard error:

Error: Not logged in to Twinfield. Run: vendor/bin/twf login

Add -v for the trace of the error.

The result of a command, such as the access token of twf token or the lines of twf office list, goes to standard output, also with --quiet. Messages for people are left out with --quiet.

Terminal window
token=$(vendor/bin/twf token)

twf status fails when there is no login:

Terminal window
if ! vendor/bin/twf status --quiet; then
vendor/bin/twf login
fi
Made by SolveBeam

Twinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.