Utility for updating, combining, filtering, or summarizing a YAML-format diag table
diag-tool [options] subcommand [table1.yaml [table2.yaml …]]
diag-tool consists of various subcommands:
edit: Edit a table interactively, then merge the changes back infilter: Apply file or variable filters to a tablelist: List the files and variables in a tablepick: Pick a single file or variable from a tablemerge: Symmetrically merge tables, failing if any conflicts occurupdate: Update a table, replacing the table's original data if any conflicts occur
The edit, filter, list, and pick subcommands expect one YAML as input, and will
read from standard input if none is provided. merge and update expect at least two
YAMLs as input; if only one is provided, they will attempt to read the lefthand YAML from
standard input.
All subcommands write to standard output by default. If the -i (--in-place) option is
used, the YAML file is overwritten instead. In the case of update or merge,
--in-place causes the most righthand YAML to be overwritten. diag-tool will ask for
confirmation before overwriting the old YAML; this can be bypassed using the -F
(--force) option.
Options:
-i(--in-place): Overwrite existing table, rather than write to standard output-F(--force): Bypass the confirmation prompt when overwriting an existing table-f FILE_FILTER(--file=FILE_FILTER): Apply a file filter.FILE_FILTERmust be of the form[~]FILE, whereFILEmay be an individual file name, a comma-separated list thereof, or*. In the case of a comma-separated list, the filter will match any of the filenames listed. The~prefix, if provided, inverts the filter so that matches are excluded rather than included.-v VAR_FILTER(--var=VAR_FILTER): Apply a variable filter.VAR_FILTERmust be of the form[~][FILE:[MODULE:]]VAR, whereFILE,MODULE, andVARmay be individual file/module/variable names, comma-separated lists thereof, or*. If comma-separated lists are provided, the filter will match the union of the Cartesian product of the lists. The~prefix, if provided, inverts the filter so that matches are excluded rather than included.-p(--prune): Prune files which have no variables remaining after filters are applied.-a [~]table|file|var(--abstract=[~]table|file|var): Exclude table-level, file-level, or variable-level attributes from the output. Multiple--abstractoptions may be provided. A~prefix disables the respective abstract option (i.e., causes attributes at the respective level to be included in the output). Specifically, the following values have the following effects:table: Hidetitleandbase_datefile: Hide all file attributes exceptfile_nameandvarlistvar: Hide all variable attributes exceptvar_name
-h(--help): Print help message and exit-V(--version): Print version number and exit
To modify an existing variable, or to add a new variable by using an existing variable as a template:
$ diag-tool -i --var=existing_file:existing_var -p -a table -a file edit diag_table.yaml
The above command applies a filter to pick out a variable called existing_var (in
existing_file) from diag_table.yaml, hides table and file attributes, drops you into
your editor of choice (customizable via the VISUAL or EDITOR env variables) to make
modifications, checks your input for validity, and merges the updates back into the
original diag_table.yaml. If you do not modify file_name or var_name while editing,
then the original variable will be updated; otherwise, a new variable (and a new file, if
needed) will be added.
The command shown above can be broken down into the following pipeline:
$ diag-tool --var=existing_file:existing_var -p -a table -a file filter diag_table.yaml | diag-tool edit | diag-tool -i update diag_table.yaml
diag-tool filterpicks out the variableexisting_varand prints it to standard output.diag-tool editdrops the user into an editor in whichexisting_varcan be modified.diag-tool updatemerges the changes back into the original table.
In the above example, notice that the filter and edit subcommands were invoked without
the -i (--in-place) option, causing them to print their results to standard output.
The --in-place option provided to the update subcommand instructs diag-tool to
overwrite the original YAML file, rather than write the merged table to standard output.
An alternative workflow could involve using diag-tool filter to create a template file:
$ diag-tool --var=existing_file:existing_var -p -a table -a file filter diag_table.yaml >~/templates/example_var.yaml
This template could then be used as the input for a subsequent pair of edit-update commands, which could perhaps be run via a shell alias:
$ alias ADDVAR="diag-tool edit ~/templates/example_var.yaml | diag-tool -i update"
$ ADDVAR my_table.yaml
To combine three tables for which no conflicts are expected:
$ diag-tool merge table1.yaml table2.yaml table3.yaml >combined.yaml
To see a summary of the files and variables contained in a table:
$ diag-tool list table.yaml
To see a summary of the variables in example_file:
$ diag-tool --file=example_file list table.yaml
To see a list of the files with all variables excluded:
$ diag-tool --var=~* list table.yaml
To remove unwanted_var (in the_file) from table.yaml:
$ diag-tool -i --var=~the_file:unwanted_var filter table.yaml
Notice the ~ prefix in the variable filter string; this causes the filter to include all
variables except the match (namely, unwanted_var in the_file) in the output.
filter and list are fundamentally the same operation. The only difference between them
is their default values for the --abstract option. In particular, the following two
commands are identical:
$ diag-tool list table.yaml
$ diag-tool -a table -a file -a var filter table.yaml
filter outputs a filtered diag table, whereas pick outputs a YAML representation of a
variable (when a variable filter is provided) or a file (when no variable filter is
provided). The resulting YAMLs are treated differently by the update and merge
subcommands.
Specifically, a file or variable YAML can only be merged into a table (via an update or
merge command) in combination with a filter which specifies which variables (files) the
variable (file) YAML is to be merged into. As an example, the command below may be used to
rename old_module to new_module across all variables in diag_table.yaml:
echo "module: new_module" | diag-tool -i --var=*:old_module:* update diag_table.yaml
Providing a variable filter to an update or merge command will cause all YAMLs except
the right-most to be interpreted as variable YAMLs. Providing a file filter without a
variable filter will cause all YAMLs except the right-most to be interpreted as file
YAMLs.
| File filter | Explanation |
|---|---|
| --file=* | Include all files |
| --file=~* | Exclude all files |
| --file=my_file | Only include the file named "my_file" |
| --file=~my_file | Exclude the file named "my_file" |
| --file=file1,file2,file3 | Include files named "file1", "file2", or "file3" |
| --file=~file1,file2,file3 | Exclude files named "file1", "file2", or "file3" |
| Variable filter | Explanation |
|---|---|
| --var=* | Include all variables |
| --var=~* | Exclude all variables |
| --var=my_var | Only include variables named "my_var" (in any file or module) |
| --var=my_file:my_var | Only include the variable "my_var" in the file "my_file" |
| --var=:my_mod: | Only include variables in the module "my_mod" |
| --var=~:my_mod: | Exclude all variables in the module "my_mod" |
| --var=~my_var | Exclude any variable named "my_var" |