Skip to content
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

lib: Add a standard parser option for JSON formatting #3704

Merged
merged 2 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions general/g.mapsets/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,7 @@ int main(int argc, char *argv[])
opt.op->description = _("Operation to be performed");
opt.op->answer = "add";

opt.format = G_define_option();
opt.format->key = "format";
opt.format->type = TYPE_STRING;
opt.format->required = YES;
opt.format->label = _("Output format for printing (-l and -p flags)");
opt.format->options = "plain,json";
opt.format->descriptions = "plain;Configurable plain text output;"
"json;JSON (JavaScript Object Notation);";
opt.format->answer = "plain";
opt.format = G_define_standard_option(G_OPT_F_FORMAT);
opt.format->guisection = _("Print");

opt.fsep = G_define_standard_option(G_OPT_F_SEP);
Expand Down
10 changes: 1 addition & 9 deletions imagery/i.signatures/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,7 @@ int main(int argc, char *argv[])
parms.type->description = _("Type of signature file");
parms.type->guisection = _("Main");

parms.format = G_define_option();
parms.format->key = "format";
parms.format->type = TYPE_STRING;
parms.format->required = NO;
parms.format->label = _("Output format");
parms.format->options = "plain,json";
parms.format->descriptions = "plain;Plain text output;"
"json;JSON (JavaScript Object Notation);";
parms.format->answer = "plain";
parms.format = G_define_standard_option(G_OPT_F_FORMAT);
parms.format->guisection = _("Print");

parms.mapset = G_define_standard_option(G_OPT_M_MAPSET);
Expand Down
4 changes: 3 additions & 1 deletion include/grass/gis.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,9 @@ typedef enum {
G_OPT_MAP_TYPE, /*!< The type of an input map: raster, vect, rast3d */
G_OPT_T_TYPE, /*!< The temporal type of a space time dataset */
G_OPT_T_WHERE, /*!< A temporal GIS framework SQL WHERE statement */
G_OPT_T_SAMPLE /*!< Temporal sample methods */
G_OPT_T_SAMPLE, /*!< Temporal sample methods */

G_OPT_F_FORMAT, /*!< set output format to plain text or JSON */
} STD_OPT;

/*!
Expand Down
11 changes: 11 additions & 0 deletions lib/gis/parser_standard_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,17 @@ struct Option *G_define_standard_option(int opt)
Opt->description =
_("The method to be used for sampling the input dataset");
break;
case G_OPT_F_FORMAT:
Opt->key = "format";
Opt->type = TYPE_STRING;
Opt->key_desc = "name";
Opt->required = YES;
Opt->label = _("Output format");
Opt->answer = "plain";
Opt->options = "plain,json";
Opt->descriptions = _("plain;Plain text output;"
"json;JSON (JavaScript Object Notation);");
break;
}

return Opt;
Expand Down
10 changes: 1 addition & 9 deletions raster/r.horizon/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,7 @@ int main(int argc, char *argv[])
parm.dist->description = _("Sampling distance step coefficient (0.5-1.5)");
parm.dist->guisection = _("Optional");

parm.format = G_define_option();
parm.format->key = "format";
parm.format->type = TYPE_STRING;
parm.format->required = YES;
parm.format->label = _("Output format used for point mode");
parm.format->options = "plain,json";
parm.format->descriptions = "plain;Plain text output;"
"json;JSON (JavaScript Object Notation);";
parm.format->answer = "plain";
parm.format = G_define_standard_option(G_OPT_F_FORMAT);
parm.format->guisection = _("Point mode");

parm.output = G_define_standard_option(G_OPT_F_OUTPUT);
Expand Down
10 changes: 1 addition & 9 deletions raster/r.kappa/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,7 @@ int main(int argc, char **argv)
parms.titles->answer = "ACCURACY ASSESSMENT";
parms.titles->guisection = _("Output settings");

parms.format = G_define_option();
parms.format->key = "format";
parms.format->type = TYPE_STRING;
parms.format->required = YES;
parms.format->label = _("Output format");
parms.format->options = "plain,json";
parms.format->descriptions = "plain;Plain text output;"
"json;JSON (JavaScript Object Notation);";
parms.format->answer = "plain";
parms.format = G_define_standard_option(G_OPT_F_FORMAT);
parms.format->guisection = _("Output settings");

flags.w = G_define_flag();
Expand Down
10 changes: 1 addition & 9 deletions raster/r.what/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,7 @@ int main(int argc, char *argv[])
opt.fs = G_define_standard_option(G_OPT_F_SEP);
opt.fs->guisection = _("Print");

opt.format = G_define_option();
opt.format->key = "format";
opt.format->type = TYPE_STRING;
opt.format->required = NO;
kritibirda26 marked this conversation as resolved.
Show resolved Hide resolved
opt.format->label = _("Output format");
opt.format->options = "plain,json";
opt.format->descriptions = "plain;Plain text output;"
"json;JSON (JavaScript Object Notation);";
opt.format->answer = "plain";
opt.format = G_define_standard_option(G_OPT_F_FORMAT);
opt.format->guisection = _("Print");

opt.cache = G_define_option();
Expand Down
7 changes: 1 addition & 6 deletions vector/v.db.select/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,13 @@ int main(int argc, char **argv)
_("GROUP BY conditions of SQL statement without 'group by' keyword");
options.group->guisection = _("Selection");

options.format = G_define_option();
options.format->key = "format";
options.format->type = TYPE_STRING;
options.format->required = YES;
options.format->label = _("Output format");
options.format = G_define_standard_option(G_OPT_F_FORMAT);
options.format->options = "plain,csv,json,vertical";
options.format->descriptions =
"plain;Configurable plain text output;"
"csv;CSV (Comma Separated Values);"
"json;JSON (JavaScript Object Notation);"
"vertical;Plain text vertical output (instead of horizontal)";
options.format->answer = "plain";
options.format->guisection = _("Format");

options.fsep = G_define_standard_option(G_OPT_F_SEP);
Expand Down
Loading