Version 8 Documentation

SmartShape CLI

About

smartshape-cli (“SmartShape Command Line Interpreter”) is a SmartShape client application with a command line interface.

It provides access to all the features of the “classic” SmartShape application (without the 3D rendering) with a command line interface that can be used to ease maintenance operations, automation and scripting.

Note: smartshape-cli is still in beta and some features are still missing. Please make sure you always upgrade to the latest version.

Usage

Use the --help switch to get the documentation for each available subcommand:

smartshape-cli --help

Output

smartshape-cli will output only the pretty-printed JSON document(s) resulting from the specified subcommand.

When stdout is not a TTY (ie when using a pipe), the smartshape-cli command will output one result JSON document per line.

Logs

Logs can be enabled by settings the SMARTSHAPE_CLI_LOG environment variable.

The value of this variable must follow the notation documented here. For example, the following command line will enable debug logs for the whole smartshape module:

export SMARTSHAPE_CLI_LOG=smartshape=debug

Configuration

Environment variables can be specified in a .env file.

Recipes

The following recipes are meant to be used in a Bash shell. Some of them rely on jq, which can be found here.

Filtering the output

jq can be used to filter/rewrite the output of smartshape-cli.

The following command will output the size of each file:

smartshape-cli file list -r | jq .size

Counting results

wc -l can be used to count the results of a command.

The following example will count the total number of files:

smartshape-cli file list -r | wc -l

Combined with jq, one can count the total number of files in an error state:

smartshape-cli file list -r \
    | jq -c 'select(.state=="inError")'
    | wc -l

Computing the total size of a directory

smartshape-cli file list /path/to/directory -r | jq -c .size | awk '{s+=$1} END {print s}'

The result can be made human readable using the numfmt command:

smartshape-cli file list /path/to/directory -r \
    | jq -c .size \
    | awk '{s+=$1} END {print s}' \
    | numfmt --to=iec --suffix=B --format='%.2f'

Run a command for each result

xargs can be used to call a command for each output of smartshape-cli. When piped, the smartshape-cli command will output one result JSON document per line. xargs can then be used to pass each output JSON document to another command.

The following command will list the configurations for all the files:

smartshape-cli file list -r \
   | xargs -n1 -0 -d"\n" -I{} bash -c "echo '{}' | jq -r .key" \
   | xargs -n1 -0 -d"\n" smartshape-cli configuration list

xargs -n1 -0 -d"\n" is used because: * -d"\n" specifies the input delimiter is the \n new line character * -n1 specifies the command should run for each input * -0 makes sure quotes and spaces are kept intact

Optionnaly, to pipe the output of smartshape-cli to the command ran by xargs, one must use -I{}. In the example above, it’s used to pass each output to jq.

Apply a configuration to each uploaded/synced file

Using xargs as explained above, one can use the following command to apply a configuration each uploaded files:

smartshape-cli file upload /path/to/file1 /path/to/file2 \
   | xargs -I{} -0 -d"\n" bash -c "echo '{}' | jq -r .key" \
   | xargs -I{} smartshape-cli configuration update {} '{"renderMode":"basic"}'

Here is how it works:

  • When piped, the smartshape-cli command will output one result JSON document per line.
  • The first call to xargs is then used to call jq on each JSON document to output the key field of each file.
  • The second call to xargs then calls smartshape-cli on each key produced by the previous command to call the configuration update subcommand.

The same can be achieved for each synced file by using the sync subcommand:

smartshape-cli sync local /path/to/sync --prefix /dest/of/sync -p \
   | xargs -I{} -0 -d"\n" bash -c "echo '{}' | jq -r .key" \
   | xargs -I{} smartshape-cli configuration update {} '{"renderMode":"basic"}'

Wait for a file to be converted

while [ `smartshape-cli file get /path/to/file | jq .state` = "converting" ]; do sleep 5; done 

Update the configuration of a selection of files

The following command line will update the configuration of all the *.dae files in the /path/to/files directory:

smartshape-cli file ls -r /path/to/files \
  | xargs -I{} -n1 -0 -d"\n" bash -c "echo '{}' | jq -r 'select(.key | endswith(\".dae\")) | .key'" \
  | xargs -I{} smartshape-cli configuration update {} '{"renderMode":"basic"}'
Last updated on 12 Jun 2019

SmartShape Documentation v8.1.0, powered by Hugo.