Skip to content

Commit fb6729a

Browse files
authored
init: Enable subcommands for the main grass command (#6442)
This enables access to the subcommands from the main _grass_ command. It keeps the commands not documented at the top level, so they remain hidden and experimental. Backwards compatibility with the classic CLI parameters should be smooth. The decision is based on the first command line argument. This will yield unexpected results (only) when path to mapset matches one of the subcommands, e.g., when naming mapset simply mapset and running the _grass_ command in the project directory which contains this mapset (same for project). It may become a bigger issue with more subcommands, but a simple workaround is prefixing the path `./`. This includes subcommands which are in other PRs, but the subcommand parser will deal with that by reporting an error. This could be an approach we take in general: reserving subcommand names even when we don't have them implemented yet (and triggering some of the directory (project, mapset, filename) issues sooner (even before a specific subcommand is fully introduced). This will is useful together with project create subcommand (#6441) and raster pack IO (#5877). Before (assuming PYTHONPATH or FHS): python -m grass.app run --crs EPSG:3358 g.proj -p After (assuming PATH): grass run --crs EPSG:3358 g.proj -p
1 parent 14923ee commit fb6729a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

lib/init/grass.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2030,6 +2030,12 @@ def parse_cmdline(argv, default_gui) -> Parameters:
20302030
20312031
Returns Parameters object used throughout the script.
20322032
"""
2033+
# For the subcommands, we keep a list here which allows us not to import
2034+
# the whole grass.app.cli module and all its dependencies.
2035+
if len(argv) > 1 and argv[1] in ["run", "project", "mapset", "help", "man"]:
2036+
from grass.app.cli import main as subcommand_cli_main
2037+
2038+
sys.exit(subcommand_cli_main())
20332039
params: Parameters = classic_parser(argv, default_gui)
20342040
validate_cmdline(params)
20352041
return params

0 commit comments

Comments
 (0)