Skip to content

Long-form command-line argument support #224

@PaulWessel

Description

@PaulWessel

With a series of GMT wrappers being built for various computational environments (MATLAB, Python, Julia for now), a key difference with the classic GMT command-line interface is the use of more human-understandable (and longer) keywords and values. For instance, the modern interfaces will use expressions like 'region=20/30/30/50' and not expose users to GMT's short-form -R20/30/30/50 option directly. Because several wrappers are being developed we should insist that the keyword/value pairs be the same for all the wrappers, subject to any language limitations of course. With that as the goal, we will be adding such parsing to the GMT library itself instead of letting all the wrappers reimplement separate parsers. The wrappers are free to go beyond our implementation but should follow our guidelines for "approved" keyword and values for such.

UNIX command-line software often have short options flags (e.g., grep -e pattern) where a single hyphen is used, whereas whole word options use two (e.g., grep --binary-files=value). Thus, it seems reasonable that GMT should follow this well-established model. This means for setting the map or data region one should be able to use either
-Rxmin/xmax/ymin/ymax
or
--region=xmin/xmax/ymin/ymax
My solution for adding such parsing to GMT is simple and already tested at the rudimentary level:

  1. All GMT common options and their long/short option names will reside in a single common structured list.

  2. Each module will have a separate local list of its module-specific long/short option structured list

  3. Each module currently starts with a call to gmt_init_module. We simply add the module-specific list as a new argument and let gmt_init_module convert any occurrence of long-usage option to the corresponding short-usage option. Then, no other changes in GMT are required (except for documentation).

  4. Initially, we may only have keywords for the common option and all module lists are NULL, but this can then be expanded as we work our way through the 140+ modules.

To start this off for discussion and feedback, here is a list of GMT's single-character common options and proposed long-name keywords:

J project, projection
R region
U timestamp
V verbosity
X xoff, xoffset
Y yoff, yoffset
a aspatial
c panel
d nodata
e find
f coltype
g gap
h header
i incols, incolumns
o outcols, outcolumns
n interpolation
p perspective
r registration
s skip
t transparency
x cores
: order

So finally, here is an example of a pscoast plot for France that uses many of these, with a mix of single-char options since module options have not been proposed yet:

gmt pscoast --region=FR --projection=M15c -Baf -Gred --timestamp --transparency=30 -pdf map

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussionTopics for longer discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions