Skip to content

Create a standardized format name for the shell script style (the g flag) #4492

@wenzeslaus

Description

@wenzeslaus

Background

Recently, we were introducing JSON outputs and in the past, we already introduced the format parameter to tools like v.db.select. One question which remains is how the key-value format usually enabled by -g should be called? Documentation usually calls it something along the lines of "shell script style". The format is usually =-separated key-value pairs, one per line and unique keys (not always though). The original idea was that it can be put directly to Bash's eval function. This is the format typically parsed in the past by grass.script.parse_command to create a Python dictionary with keys and values provided by -g (side note: now that parses JSON as well but still defaults to expecting =-separated key-values).

Question

How the following flag should be replaced with a format option/parameter? Specifically, which value to use for the format option?

  -g   Print the stats in shell script style

Examples

This flag is, for example, found in r.univar and format option allows switching only between plain and json. -g right now acts as a modifier of the plain format. However, the idea is to present that as its own format which is likely more precise and fits with other tools with multiple formats. See these formats in v.db.select:

plain: Configurable plain text output
csv: CSV (Comma Separated Values)
json: JSON (JavaScript Object Notation)
vertical: Plain text vertical output (instead of horizontal)

r.univar has only:

plain: Plain text output
json: JSON (JavaScript Object Notation)

but should have something like:

plain: Plain text output
json: JSON (JavaScript Object Notation)
shell: Shell script style

Suggestions

Options:

shell: Shell script style
bash: Shell script style
bash: Bash-like script style
bash: Bash-like key-value pairs
bash: Key-value pairs in Bash-like syntax
eval: Values in Bash eval syntax
key-value: Key-value pairs in Bash-like syntax
keyval: Key-value pairs separated by equal sign

Feel free to add your suggestions or combinations of the above.

The description will be easy to change in the future, but the value is part of the API, so we need to set it and stick to it. Thus, the big decision is really between sh, shell, bash, script, eval, key-value, keyvalue, keyval, eqsep, ...

Implementation in v8 versus v9

In v8, we would add this to existing tools which now have format option and -g flag, for example r.univar. -g would stay there for compatibility. In v9, we can remove -g and only format would be used to change the output format. (This is similar to what happened with -v Vertical output (instead of horizontal) in v.db.select between v7 and v8.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    blockerBlocking a releaseenhancementNew feature or request

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions