Scripting
The commands of twf are made to be used in scripts, like those of gh.
Output in a terminal and in a pipe
Section titled “Output in a terminal and in a pipe”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.
vendor/bin/twf office list | cut -f1twf 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:
vendor/bin/twf office list --json | jq -r '.[] | select(.country == "NL") | .code'Exit status
Section titled “Exit status”| 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 loginAdd -v for the trace of the error.
The result is always printed
Section titled “The result is always printed”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.
token=$(vendor/bin/twf token)Check for a login
Section titled “Check for a login”twf status fails when there is no login:
if ! vendor/bin/twf status --quiet; then vendor/bin/twf loginfiTwinfield and Wolters Kluwer are trademarks of Wolters Kluwer. Their names and logos are used only to refer to their products.