Output Formatting
The ODIN CLI supports various output formats to accommodate different needs, such as human-readable formats for direct interaction and machine-readable formats for scripts and automation.
Basics
The output format can be set using the --format
flag. If omitted, the default format is used that is specific to each
command. If values to be printed in tables or as a value are objects or arrays, they are automatically converted to JSON
format.
I.e. the Servers object has a hash map of ports. If you want to print the published ports of your server, you can use the following command:
This will output a table with the server ID, IP address, and the ports object in JSON format. You can also access nested properties by using the dot syntax. If you want to print the published game port of your server, you can use the following command:
The Game Port
is the name of the port configuration you created in the server configuration. The publishedPort
is
the
port that is actually used by the server.
Default Output
The default format is human-readable and designed to be intuitive for each command.
JSON Output
The json
format outputs the command results in JSON format, conforming to the API specifications. This is useful for
processing data programmatically.
Table Output
The table(propertyList)
format prints the result in a table format. The propertyList
is a comma-separated list of
properties you want to display as table columns. Nested properties can be accessed using the dot syntax (e.g.,
serverConfig.id
).
Example:
This would display a table with columns with the id
, the servers IP address and the published game port.
Flattened Output
The flattened[noPad,separator='->'](propertyList)
format prints a simple key value pair output, where each property is
displayed on a new line. The separator
attribute allows you to define a custom separator between the key and value.
Optional Attributes:
- noPad: Disables padding, resulting in a more compact output.
- separator: Changes the default separator (
:
) to any other character(s).
Example:
This would output:
Value Output
The value[separator='->'](propertyList)
format prints only the values of the specified properties in a single line,
separated by the chosen separator (default is tab).
Optional Attributes:
- separator: An optional attribute that lets you define a custom separator for the values.
Examples:
This would output:
It's a powerful tool for extracting specific information from the output of a command. I.e. it's super useful in scripts
or automation tasks. For example when creating an item you can use the value
format to just get the ID of the created
item. That can easily be used in the next command.
This would store the ID of the created image in the IMAGE_ID
variable.
Advanced Property Lists
Property lists can be very flexible and powerful, especially when dealing with nested data or arrays. Here are some advanced examples:
Accessing Nested Properties
Output:
Indexing Arrays
This would output the first key-value pair in the env
array.
Functions
Functions can be used in the property list to manipulate the data before it is printed. Functions have this format:
functionName(parameter)
.
While parameters in the property list are acting on individual items in the data, functions are acting on the entire
dataset. Example: You have a list with 5 items. value(id)
will return the ID of each item, while value(count(id))
will
iterate over each item in the dataset and return the number of items that have an ID (so all of them).
You can combine functions with parameters, but that might not always make sense. For example, value(count(id),id)
would return something like this:
Counting Items
Parameters in the property list can also be functions. This can be useful for counting items. For example, to count the number of configs. You can also combine that with filters to count specific items.
Return the number of running servers: