[GRASS-dev] RFC: Module Option Parser
Glynn Clements
glynn at gclements.plus.com
Fri Dec 15 04:22:21 EST 2006
Brad Douglas wrote:
> I'm in the process of updating/upgrading the imagery libraries and
> modules. I have run into a problem which I wish to simplify, but would
> require modification of lib/gis/parser.c, etc.
>
> I think we can all agree that i.ortho.photo is a mess and hasn't been
> able to evolve as the rest of GRASS has. I want to remove as much
> interactivity as possible, but that creates a dilemma:
>
> A) I can break i.ortho.photo into 7-8 separate modules, or
> B) I can make it a single module by using the following structure:
I strongly favour option A; see below.
> Option A does not set well with me and Markus has agreed, privately, due
> to the ever growing list of GRASS modules, so I need something a bit
> 'better'.
>
> - Create an Option that allows to select from a series of commands like
> v.build does:
>
> tool_opt = G_define_option ();
> tool_opt->key = "tool";
> tool_opt->type = TYPE_STRING;
> tool_opt->required = YES;
> tool_opt->multiple = NO;
> tool_opt->description = _("The ortho tool to use:\n"
> "\t\ttarget - Target imagery location and mapset\n"
> "\t\tdem - Digital Elevation Model (elevation)\n"
> "\t\tcamera - Camera parameters\n"
> "\t\ttransform - Transformation parameters\n"
> "\t\texposure - Exposure parameters\n"
> "\t\tparams - Ortho photo parameters\n"
> "\t\trectify - Rectify the ortho photo");
> tool_opt->options =
> "target,dem,camera,transform,exposure,params,rectify";
>
> ...but alter it a bit, namely changing the first line to:
> tool_opt = G_define_selection(), a new function.
>
> In order to make this work and keep the many options from spamming
> i.ortho.photo --help (as many of the above selections have multiple
> options that are not related to each other), I would like to propose the
> following changes:
>
> - Create a new function: G_define_selection ();
> - Add another option to G_define_option () that would link an option to
> a selection:
> dem_opt = G_define_option ();
> dem_opt->key = "dem";
> dem_opt->type = TYPE_STRING;
> dem_opt->required = NO;
> dem_opt->multiple = NO;
> dem_opt->description = _("Digital Elevation Model");
> --> dem_opt->selection = "dem"; <--- new option
>
> So...when I do 'i.ortho.photo --help', I get a list of selections to
> choose from. When I do, 'i.ortho.photo select=dem --help', I only get a
> list of options associated with the "dem" selection (ie. dem_opt).
>
> Comments, suggestions, and better ideas are always welcome.
Extending the infrastructure for a single module is normally a clue
that the problem is with the module.
If most of the options only apply to a specific "mode", that suggests
that each mode should be implemented as a separate module. If they
share common code, make it a library.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list