20 #include "parser_local_proto.h"
22 static void print_python_short_flag(FILE *
file,
const char *key,
23 const char *label,
const char *description,
25 static void print_python_long_flag(FILE *
file,
const char *key,
26 const char *label,
const char *description,
28 static void print_python_option(FILE *
file,
const struct Option *opt,
30 static void print_python_example(FILE *
file,
const char *python_function,
31 const char *output_format_default,
33 static void print_python_tuple(FILE *
file,
const char *type,
int num_items);
35 void print_python_short_flag(FILE *
file,
const char *key,
const char *label,
36 const char *description,
const char *indent)
38 fprintf(
file,
"%s", indent);
40 fprintf(
file,
"**%s**", key);
41 fprintf(
file, MD_NEWLINE);
44 fprintf(
file,
"%s", indent);
47 fprintf(
file, MD_NEWLINE);
50 if (description !=
NULL) {
51 fprintf(
file,
"%s", indent);
57 void print_python_long_flag(FILE *
file,
const char *key,
const char *label,
58 const char *description,
const char *indent)
60 fprintf(
file,
"%s**%s**: bool, *optional*", indent, key);
61 fprintf(
file, MD_NEWLINE);
64 fprintf(
file,
"%s", indent);
67 fprintf(
file, MD_NEWLINE);
70 if (description !=
NULL) {
71 fprintf(
file,
"%s", indent);
74 fprintf(
file, MD_NEWLINE);
77 fprintf(
file,
"%s", indent);
79 fprintf(
file,
"Default: *False*");
82 void print_python_tuple(FILE *
file,
const char *type,
int num_items)
84 fprintf(
file,
"tuple[%s", type);
85 for (
int i = 1; i < num_items; i++) {
86 fprintf(
file,
", %s", type);
91 void print_python_option(FILE *
file,
const struct Option *opt,
110 fprintf(
file,
"%s**%s** : ", indent, opt->
key);
114 fprintf(
file,
"list[");
115 print_python_tuple(
file, type, tuple_items);
116 fprintf(
file,
"] | ");
117 print_python_tuple(
file, type, tuple_items);
118 fprintf(
file,
" | list[%s] | str", type);
121 if (strcmp(type,
"str")) {
126 fprintf(
file,
"%s | list[%s] | str", type, type);
129 fprintf(
file,
"%s | list[%s]", type, type);
133 else if (tuple_items) {
134 print_python_tuple(
file, type, tuple_items);
135 fprintf(
file,
" | list[%s] | str", type);
138 fprintf(
file,
"%s", type);
141 fprintf(
file,
", *required*");
144 fprintf(
file,
", *optional*");
147 fprintf(
file, MD_NEWLINE);
150 fprintf(
file,
"%s", indent);
156 fprintf(
file, MD_NEWLINE);
159 fprintf(
file,
"%s", indent);
164 fprintf(
file, MD_NEWLINE);
166 fprintf(
file,
"%s", indent);
168 fprintf(
file,
"%s: ",
_(
"Used as"));
173 char desc[KEYLENGTH];
175 if (strcmp(age,
"new") == 0)
176 fprintf(
file,
"output, ");
177 else if (strcmp(age,
"old") == 0)
178 fprintf(
file,
"input, ");
183 fprintf(
file,
"%s", desc);
193 fprintf(
file, MD_NEWLINE);
195 fprintf(
file,
"%s", indent);
197 fprintf(
file,
"%s: *",
_(
"Allowed values"));
205 while (opt->
opts[i]) {
207 fprintf(
file, MD_NEWLINE);
209 fprintf(
file,
"%s", indent);
210 char *thumbnails =
NULL;
212 if (strcmp(opt->
gisprompt,
"old,colortable,colortable") ==
214 thumbnails =
"colortables";
215 else if (strcmp(opt->
gisprompt,
"old,barscale,barscale") ==
217 thumbnails =
"barscales";
219 "old,northarrow,northarrow") == 0)
220 thumbnails =
"northarrows";
224 fprintf(
file,
" ", opt->
opts[i],
225 thumbnails, opt->
opts[i]);
234 fprintf(
file,
"**: ");
242 fprintf(
file, MD_NEWLINE);
244 fprintf(
file,
"%s", indent);
246 fprintf(
file,
"%s:",
_(
"Default"));
253 void print_python_example(FILE *
file,
const char *python_function,
254 const char *output_format_default,
const char *indent)
256 fprintf(
file,
"\n%sExample:\n", indent);
258 fprintf(
file,
"\n%s```python\n", indent);
259 fprintf(
file,
"%sgs.%s(\"%s\"", indent, python_function,
st->pgm_name);
261 const struct Option *first_required_rule_option =
267 opt = &
st->first_option;
269 while (opt !=
NULL) {
287 if (opt->
required || first_required_rule_option == opt) {
288 fprintf(
file,
", %s=", opt->
key);
289 if (output_format_default && strcmp(opt->
key,
"format") == 0) {
290 fprintf(
file,
"\"%s\"", output_format_default);
312 fprintf(
file,
")\n%s```\n", indent);
320 bool output_format_option =
false;
321 const char *output_format_default =
NULL;
322 bool shell_eval_flag =
false;
323 const char *python_function =
NULL;
328 opt = &
st->first_option;
329 while (opt !=
NULL) {
330 if (strcmp(opt->
key,
"format") == 0) {
333 while (opt->
opts[i]) {
334 if (strcmp(opt->
opts[i],
"csv") == 0)
335 output_format_default =
"csv";
336 if (strcmp(opt->
opts[i],
"json") == 0) {
337 output_format_default =
"json";
343 if (output_format_default) {
344 output_format_option =
true;
352 flag = &
st->first_flag;
353 while (
st->n_flags && flag !=
NULL) {
354 if (flag->
key ==
'g') {
355 shell_eval_flag =
true;
361 if (output_format_option || (!new_prompt && shell_eval_flag)) {
362 python_function =
"parse_command";
368 python_function =
"run_command";
370 fprintf(
file,
"%s*grass.script.%s*(\"***%s***\",", indent, python_function,
375 opt = &
st->first_option;
377 while (opt !=
NULL) {
378 fprintf(
file,
"%s ", indent);
380 fprintf(
file,
"**%s**=*None*", opt->
key);
383 fprintf(
file,
"**%s**", opt->
key);
395 fprintf(
file,
"*\"");
397 fprintf(
file,
"\"*");
400 fprintf(
file,
",\n");
407 flag = &
st->first_flag;
408 fprintf(
file,
"%s **flags**=*None*,\n", indent);
412 fprintf(
file,
"%s **overwrite**=*False*,\n", indent);
414 fprintf(
file,
"%s **verbose**=*False*,\n", indent);
415 fprintf(
file,
"%s **quiet**=*False*,\n", indent);
416 fprintf(
file,
"%s **superquiet**=*False*)\n", indent);
418 print_python_example(
file, python_function, output_format_default, indent);
431 opt = &
st->first_option;
432 while (opt !=
NULL) {
433 print_python_option(
file, opt, indent);
435 fprintf(
file, MD_NEWLINE);
442 fprintf(
file,
"%s**flags** : str, *optional*", indent);
443 fprintf(
file, MD_NEWLINE);
445 fprintf(
file,
"%s", indent);
447 fprintf(
file,
"Allowed values: ");
448 flag = &
st->first_flag;
449 while (
st->n_flags && flag !=
NULL) {
450 fprintf(
file,
"*%s*", &flag->
key);
455 fprintf(
file, MD_NEWLINE);
457 flag = &
st->first_flag;
458 while (
st->n_flags && flag !=
NULL) {
461 fprintf(
file, MD_NEWLINE);
467 print_python_long_flag(
469 _(
"Allow output files to overwrite existing files"), indent);
470 fprintf(
file, MD_NEWLINE);
474 print_python_long_flag(
file,
"verbose",
NULL,
_(
"Verbose module output"),
476 fprintf(
file, MD_NEWLINE);
478 print_python_long_flag(
file,
"quiet",
NULL,
_(
"Quiet module output"),
480 fprintf(
file, MD_NEWLINE);
482 print_python_long_flag(
file,
"superquiet",
NULL,
483 _(
"Very quiet module output"), indent);
484 fprintf(
file, MD_NEWLINE);
int G__uses_new_gisprompt(void)
void G__split_gisprompt(const char *gisprompt, char *age, char *element, char *desc)
const struct Option * G__first_required_option_from_rules(void)
void G__md_print_escaped(FILE *f, const char *str)
int G__option_num_tuple_items(const struct Option *opt)
Get number of tuple items if option is a tuple.
void G__md_print_escaped_for_options(FILE *f, const char *str)
void G__md_print_python_long_version(FILE *file, const char *indent)
void G__md_print_python_short_version(FILE *file, const char *indent)
Structure that stores flag info.
Structure that stores option information.