Skip to content

Conversation

@ninsbl
Copy link
Member

@ninsbl ninsbl commented Dec 5, 2025

This PR adds support for extended flags (--overwrite, --verbose, --quiet) to the --json flag and extends the documentation of available functionality in --json.

Replaces #2937

@ninsbl ninsbl added this to the 8.5.0 milestone Dec 5, 2025
@ninsbl ninsbl requested a review from wenzeslaus December 5, 2025 22:34
@ninsbl ninsbl added manual Documentation related issues C Related code is in C markdown Related to markdown, markdown files general labels Dec 5, 2025
@wenzeslaus
Copy link
Member

There is also super quiet.

@ninsbl
Copy link
Member Author

ninsbl commented Dec 7, 2025

There is also super quiet.

Right, but superquiet cannot be invoked from the CLI, or can it? The man / CLI documents only verbose and quiet. And the CLI is what the JSON output of the parser should reflect, no? It is invoked by actinia at the end anyway...

@wenzeslaus
Copy link
Member

See the new 8.5 doc. It should be there. Also, in the past, it was broken in the run_command function, but that's fixed now.

@ninsbl
Copy link
Member Author

ninsbl commented Dec 8, 2025

Hm... I have tried to figure out how to detect superquiet mode, but did not manage without changing the parser handling of --qq.
I found this,

grass/lib/gis/parser.c

Lines 573 to 587 in d3c6479

/* Super quiet option */
else if (strcmp(ptr, "--qq") == 0) {
char buff[32];
/* print nothing, but errors */
st->module_info.verbose = G_verbose_min();
snprintf(buff, sizeof(buff), "GRASS_VERBOSE=%d",
G_verbose_min());
putenv(G_store(buff));
G_suppress_warnings(TRUE);
if (st->quiet == -1) {
G_warning(_("Use either --qq or --verbose flag, not both. "
"Assuming --qq."));
}
st->quiet = 1; /* for passing to gui init */
However, G_Verbose_min() returns 0 as MINLEVEL also with --qq.

I tried setting GRASS_VERBOSE to -1 if the --qq flag is set...

@wenzeslaus
Copy link
Member

The detection must be somewhere in G_warning because it disables warnings.

@ninsbl
Copy link
Member Author

ninsbl commented Dec 13, 2025

The detection must be somewhere in G_warning because it disables warnings.

G_warning receives an extra parameter to not print a warning. So, that does not seem to work here. I added superquiet to the state struct in the parser, similar to quiet, verbose, and overwrite. Hope that is an acceptable solution?

Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going in the right direction. I see issue with initialization. I investigated a little bit in parser.c and error.c, but did not come to any specific conclusion. You need to check how st is initialized and make sure all the variables (attributes of st) you are using initialized. It seems to me that even the quiet and verbose are potentially wrong. If you already went through this, just let me know what you find out.

Comment on lines 281 to 292

Many GRASS modules produce textual output to stdout and actinia allows
to export that output as well, however, the **--json** flag does not yet
allow to specify export of stdout which may look in an actinia processing
chain e.g. like this:

```json
{
...
'stdout': {'id': 'stats', 'format': 'kv', 'delimiter': '='},
}
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not clear. What a user is supposed to do here? I'm missing something like "So, to do X, do A, B and C."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the updated text...

lib/gis/parser.c Outdated
"both. Assuming --verbose."));
}
st->quiet = -1;
st->superquiet = -1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is suspicions as it is not initialized anywhere.

lib/gis/parser.c Outdated
G_warning(_("Use either --qq or --verbose flag, not "
"both. Assuming --verbose."));
}
st->superquiet = 0; /* for passing to gui init */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably set a bool to either true or false for future compatibility (see https://en.cppreference.com/w/c/language/bool_constant.html).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7197c4a

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For real bool value (as in the case with the change to bool superquiet;) lowercase true and false should be used. Uppercase variants are macros defined in:

/* For boolean values and comparisons use the C99 type 'bool' with values 'true'
*/
/* and 'false' For historical reasons 'TRUE' and 'FALSE' are still valid. */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

and are used in int-based boolean functionality, e.g.:

int G_suppress_warnings(int);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to lowercase for superquiet.

lib/gis/parser.c Outdated

/* print everything: max verbosity level */
st->module_info.verbose = G_verbose_max();
snprintf(buff, sizeof(buff), "GRASS_VERBOSE=%d",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With G_set_verbose() added, may this snprintf + putenv blocks be removed?

When i ran some local tests, it does not seem to have any effect after the first time such a block had run, e.g. if users provide both --v and --pp.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With G_set_verbose() added, may this snprintf + putenv blocks be removed?

I believe it can, G_set_verbose() is the dedicated API for just this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the snprintf + putenv blocks.

@ninsbl ninsbl requested a review from wenzeslaus December 21, 2025 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C docs general libraries manual Documentation related issues markdown Related to markdown, markdown files module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants