-
-
Notifications
You must be signed in to change notification settings - Fork 360
g.list: Add JSON support #5921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
g.list: Add JSON support #5921
Conversation
Signed-off-by: Nishant Bansal <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just couple minor points.
general/g.list/list.c
Outdated
G_json_object_set_string(map_object, "mapset", el[i].mapset); | ||
G_json_object_set_string(map_object, "name", el[i].name); | ||
G_json_object_set_string(map_object, "type", el[i].type); | ||
G_json_object_set_string(map_object, "fullname", fullname); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's switch the order to have name, mapset, type, fullname:
G_json_object_set_string(map_object, "mapset", el[i].mapset); | |
G_json_object_set_string(map_object, "name", el[i].name); | |
G_json_object_set_string(map_object, "type", el[i].type); | |
G_json_object_set_string(map_object, "fullname", fullname); | |
G_json_object_set_string(map_object, "mapset", el[i].mapset); | |
G_json_object_set_string(map_object, "name", el[i].name); | |
G_json_object_set_string(map_object, "type", el[i].type); | |
G_json_object_set_string(map_object, "fullname", fullname); |
general/g.list/g.list.md
Outdated
```python | ||
import grass.script as gs | ||
|
||
data = gs.parse_command("g.list", type=["rast", "vect"], format="json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
data = gs.parse_command("g.list", type=["rast", "vect"], format="json") | |
data = gs.parse_command("g.list", type=["raster", "vect"], format="json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The messaging around -p needs to be little different here because the default format here is "shell" and there is a special flag for plain (while most of the other tools have default "plain" with -g for shell).
general/g.list/g.list.md
Outdated
@@ -27,7 +33,7 @@ g.list type=vector -m | |||
List all raster and vector maps ordered by mapset: | |||
|
|||
```sh | |||
g.list type=raster -p | |||
g.list type=raster format=plain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-p
is for interactive use, so typing format=plain
does not make much sense. While not ideal, in this case, -p
needs to stay as is for now, so here:
g.list type=raster format=plain | |
g.list type=raster,vector -p |
(I'm also fixing the type to align with the description above that.)
general/g.list/g.list.md
Outdated
@@ -27,7 +33,7 @@ g.list type=vector -m | |||
List all raster and vector maps ordered by mapset: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
List all raster and vector maps ordered by mapset: | |
List all raster and vector maps grouped by mapset in plain format: |
general/g.list/g.list.md
Outdated
The flags `-p` and `-f` apply only to plain format output, but they are now | ||
deprecated and will be removed in a future release. Instead of using those, use | ||
`format=plain` to obtain human-readable plain text output. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The flags `-p` and `-f` apply only to plain format output, but they are now | |
deprecated and will be removed in a future release. Instead of using those, use | |
`format=plain` to obtain human-readable plain text output. | |
The flags `-p` and `-f` apply only to plain format output, but they are now | |
deprecated and will be removed in a future release. Instead of using those, use | |
`format="plain"` to obtain human-readable, plain text output. The plain format will | |
become the default in a future release. | |
To obtain machine readable output use `format="shell"` or `format="json"`. |
general/g.list/g.list.md
Outdated
```python | ||
import grass.script as gs | ||
|
||
data = gs.parse_command("g.list", type=["rast", "vect"], format="json") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the shorter versions work, the full versions are the best practice for a Python script.
data = gs.parse_command("g.list", type=["rast", "vect"], format="json") | |
data = gs.parse_command("g.list", type=["raster", "vector"], format="json") |
general/g.list/g.list.md
Outdated
### Mapset search path | ||
|
||
If **mapset** is not specified, then *g.list* searches for data files in | ||
the mapsets that are included in the search path (defined by | ||
*[g.mapsets](g.mapsets.md)*). See `g.mapsets -p`. | ||
|
||
```sh | ||
g.list rast -p | ||
g.list rast format=plain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g.list rast format=plain | |
g.list rast -p |
general/g.list/g.list.md
Outdated
@@ -72,7 +93,7 @@ available mapsets also including those that are not listed in the | |||
current search path (see `g.mapsets -l`). | |||
|
|||
```sh | |||
g.list rast mapset=* -p | |||
g.list rast mapset=* format=plain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g.list rast mapset=* format=plain | |
g.list rast mapset=* -p |
general/g.list/main.c
Outdated
"This flag is deprecated and will be removed in a future release. Use " | ||
"format=plain instead."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This better describes the situation. Let me know if it makes sense:
"This flag is deprecated and will be removed in a future release. Use " | |
"format=plain instead."); | |
"This flag is deprecated and will be removed in a future release. The " | |
"plain format will become the default. Use format=\"plain\" to set it " | |
"explicitly in a script."); |
general/g.list/main.c
Outdated
flag.full->description = _("Verbose listing (also list map titles)"); | ||
flag.full->label = _("Verbose listing (also list map titles) [deprecated]"); | ||
flag.full->description = | ||
_("This flag is deprecated and will be removed in a future release."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is little nicer to tell user what to do instead:
_("This flag is deprecated and will be removed in a future release."); | |
_("This flag is deprecated and will be removed in a future release. " | |
" Use the type-specific tool to obtain metadata, such as r.info " | |
"and v.info."); |
general/g.list/main.c
Outdated
G_verbose_message( | ||
_("Flag 'p' is deprecated and will be removed in a future " | ||
"release. Please use format=plain instead.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
G_verbose_message( | |
_("Flag 'p' is deprecated and will be removed in a future " | |
"release. Please use format=plain instead.")); | |
// Do not switch this to a warning until v9. The depreciation is | |
// documented, but warning would be too distracting given the | |
// likely interactive use of this flag. In v9.0, either remove it | |
// or make this into a warning and remove it in v9.1. | |
G_verbose_message( | |
_("Flag 'p' is deprecated and will be removed in a future " | |
"release where plain will be the default format. Use " | |
"format=\"plain\" to set plain format for scripting.")); |
Signed-off-by: Nishant Bansal <[email protected]>
Fixes: #5848
This PR adds JSON support to the
g.list
module. The JSON output looks like:This PR includes the following changes:
format
option withplain
,shell
, andjson
modes for output formatting.-m
and-t
apply only whenformat=shell
.-p
is deprecated; useformat=plain
instead. The flag-f
is also deprecated.