Skip to content

Commit 5b0da01

Browse files
joa-quimclaude
andauthored
kwargs protection: core GMT modules (#1920)
Split entry points from main logic in core module wrappers so that kwargs are converted to Dict{Symbol,Any} via init_module in thin wrappers before calling the main function. Affected modules: blocks (blockmean/blockmedian/blockmode), filter1d, fitcircle, gmt2kml, gmtconnect, gmtregress, gmtselect, gmtset, gmtsimplify, gmtvector, gmtwhich, earthtide, kml2gmt, movie, project, mapproject. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 47cbdcd commit 5b0da01

16 files changed

Lines changed: 109 additions & 65 deletions

src/blocks.jl

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,17 @@ Parameters
5555
5656
To see the full documentation type: ``@? blockmean``
5757
"""
58-
blockmean(cmd0::String; kwargs...) = blockmean_helper(cmd0, nothing; kwargs...)
59-
blockmean(arg1; kwargs...) = blockmean_helper("", arg1; kwargs...)
58+
blockmean(cmd0::String; kw...) = blockmean_helper(cmd0, nothing; kw...)
59+
blockmean(arg1; kw...) = blockmean_helper("", arg1; kw...)
6060

6161
# ---------------------------------------------------------------------------------------------------
62-
function blockmean_helper(cmd0::String, arg1; kwargs...)
63-
64-
d = KW(kwargs)
62+
function blockmean_helper(cmd0::String, arg1; kw...)
63+
d = KW(kw)
6564
help_show_options(d) # Check if user wants ONLY the HELP mode
65+
blockmean_helper(cmd0, arg1, d)
66+
end
67+
function blockmean_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
68+
6669
cmd = parse_these_opts("", d, [[:E :extend :extended], [:S :statistic]])
6770
if (find_in_dict(d, [:npts :count])[1] !== nothing) cmd = " -Sn"
6871
elseif (find_in_dict(d, [:mean])[1] !== nothing) cmd = " -Sm"
@@ -73,7 +76,7 @@ function blockmean_helper(cmd0::String, arg1; kwargs...)
7376
(!occursin(" -E", cmd) && (occursin("s", opt_A) || occursin("h", opt_A) || occursin("l", opt_A))) && (opt_A *= " -E")
7477
cmd *= opt_A
7578

76-
common_blocks(cmd0, arg1, d, cmd, "blockmean", kwargs...)
79+
common_blocks(cmd0, arg1, d, cmd, "blockmean")
7780
end
7881

7982
# ---------------------------------------------------------------------------------------------------
@@ -84,19 +87,22 @@ Block average (x,y,z) data tables by L1 norm.
8487
8588
To see the full documentation type: ``@? blockmedian``
8689
"""
87-
blockmedian(cmd0::String; kwargs...) = blockmedian_helper(cmd0, nothing; kwargs...)
88-
blockmedian(arg1; kwargs...) = blockmedian_helper("", arg1; kwargs...)
90+
blockmedian(cmd0::String; kw...) = blockmedian_helper(cmd0, nothing; kw...)
91+
blockmedian(arg1; kw...) = blockmedian_helper("", arg1; kw...)
8992

9093
# ---------------------------------------------------------------------------------------------------
91-
function blockmedian_helper(cmd0::String, arg1; kwargs...)
92-
93-
d = KW(kwargs)
94+
function blockmedian_helper(cmd0::String, arg1; kw...)
95+
d = KW(kw)
9496
help_show_options(d) # Check if user wants ONLY the HELP mode
97+
blockmedian_helper(cmd0, arg1, d)
98+
end
99+
function blockmedian_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
100+
95101
cmd = parse_these_opts("", d, [[:E :extend :extended], [:Q :quick], [:T :quantile]])
96102
opt_A = add_opt(d, "", "A", [:A :field :fields], (median="_z", scale="_s", highest="_h", lowest="_l", weight="_w", weights="_w"))
97103
(!occursin(" -E", cmd) && (occursin("s", opt_A) || occursin("h", opt_A) || occursin("l", opt_A))) && (opt_A *= " -E")
98104
cmd *= opt_A
99-
common_blocks(cmd0, arg1, d, cmd, "blockmedian", kwargs...)
105+
common_blocks(cmd0, arg1, d, cmd, "blockmedian")
100106
end
101107

102108
# ---------------------------------------------------------------------------------------------------
@@ -107,23 +113,26 @@ Block average (x,y,z) data tables by mode estimation.
107113
108114
To see the full documentation type: ``@? blockmode``
109115
"""
110-
blockmode(cmd0::String; kwargs...) = blockmode_helper(cmd0, nothing; kwargs...)
111-
blockmode(arg1; kwargs...) = blockmode_helper("", arg1; kwargs...)
116+
blockmode(cmd0::String; kw...) = blockmode_helper(cmd0, nothing; kw...)
117+
blockmode(arg1; kw...) = blockmode_helper("", arg1; kw...)
112118

113119
# ---------------------------------------------------------------------------------------------------
114-
function blockmode_helper(cmd0::String, arg1; kwargs...)
120+
function blockmode_helper(cmd0::String, arg1; kw...)
121+
d = init_module(false, kw...)[1]
122+
blockmode_helper(cmd0, arg1, d)
123+
end
124+
function blockmode_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
115125

116-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
117126
cmd = parse_these_opts("", d, [[:D :histogram_binning], [:E :extend :extended], [:Q :quick]])
118127
opt_A = add_opt(d, "", "A", [:A :field :fields], (mode="_z", scale="_s", highest="_h", lowest="_l", weight="_w", weights="_w"))
119128
(!occursin(" -E", cmd) && (occursin("s", opt_A) || occursin("h", opt_A) || occursin("l", opt_A))) && (opt_A *= " -E")
120129
cmd *= opt_A
121130

122-
common_blocks(cmd0, arg1, d, cmd, "blockmode", kwargs...)
131+
common_blocks(cmd0, arg1, d, cmd, "blockmode")
123132
end
124133

125134
# ---------------------------------------------------------------------------------------------------
126-
function common_blocks(cmd0, arg1, d, cmd, proggy, kwargs...)
135+
function common_blocks(cmd0, arg1, d, cmd, proggy)
127136

128137
cmd = parse_these_opts(cmd, d, [[:C :center], [:W :weights]])
129138
opt_G = parse_G(d, "")[1]

src/filter1d.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ To see the full documentation type: ``@? filter1d``
4242
filter1d(cmd0::String; kw...) = filter1d_helper(cmd0, nothing; kw...)
4343
filter1d(arg1; kw...) = filter1d_helper("", arg1; kw...)
4444

45-
function filter1d_helper(cmd0::String, arg1; kwargs...)
46-
47-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
45+
function filter1d_helper(cmd0::String, arg1; kw...)
46+
d = init_module(false, kw...)[1]
47+
filter1d_helper(cmd0, arg1, d)
48+
end
49+
function filter1d_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
4850

4951
cmd, = parse_common_opts(d, "", [:V_params :b :d :e :f :g :h :i :o :yx])
5052
cmd = parse_these_opts(cmd, d, [[:D :inc :increment], [:E :end :ends], [:L :gap_width],

src/fitcircle.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ Parameters
1818
1919
To see the full documentation type: ``@? fitcircle``
2020
"""
21-
fitcircle(cmd0::String; kwargs...) = fitcircle_helper(cmd0, nothing; kwargs...)
22-
fitcircle(arg1; kwargs...) = fitcircle_helper("", arg1; kwargs...)
21+
fitcircle(cmd0::String; kw...) = fitcircle_helper(cmd0, nothing; kw...)
22+
fitcircle(arg1; kw...) = fitcircle_helper("", arg1; kw...)
2323

2424
# ---------------------------------------------------------------------------------------------------
25-
function fitcircle_helper(cmd0::String, arg1; kwargs...)
25+
function fitcircle_helper(cmd0::String, arg1; kw...)
26+
d = init_module(false, kw...)[1]
27+
fitcircle_helper(cmd0, arg1, d)
28+
end
29+
function fitcircle_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
2630

27-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
2831
cmd, = parse_common_opts(d, "", [:V_params :bi :di :e :f :g :h :i :o :yx])
2932
cmd = parse_these_opts(cmd, d, [[:L :norm], [:S :small_circle]])
3033
((val = find_in_dict(d, [:F :coord :coordinates])[1]) !== nothing) && (cmd *= " -F" * arg2str(val)[1])

src/geodesy/earthtide.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ See full GMT docs at [`earthtide`]($(GMTdoc)supplements/geodesy/earthtide.html)
1010
imshow(G)
1111
```
1212
"""
13-
function earthtide(; kwargs...)
14-
15-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
13+
function earthtide(; kw...)
14+
d = init_module(false, kw...)[1]
15+
earthtide(d)
16+
end
17+
function earthtide(d::Dict{Symbol, Any})
1618

1719
cmd = "earthtide " * parse_common_opts(d, "", [:R :I :V_params :r])[1]
1820
cmd = parse_opt_range(d, cmd, "T")[1]

src/gmt2kml.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,15 @@ Parameters
6767
6868
To see the full documentation type: ``@? gmt2kml``
6969
"""
70-
gmt2kml(cmd0::String; kwargs...) = gmt2kml_helper(cmd0, nothing; kwargs...)
71-
gmt2kml(arg1; kwargs...) = gmt2kml_helper("", arg1; kwargs...)
70+
gmt2kml(cmd0::String; kw...) = gmt2kml_helper(cmd0, nothing; kw...)
71+
gmt2kml(arg1; kw...) = gmt2kml_helper("", arg1; kw...)
7272

7373
# ---------------------------------------------------------------------------------------------------
74-
function gmt2kml_helper(cmd0::String, arg1; kwargs...)
75-
76-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
74+
function gmt2kml_helper(cmd0::String, arg1; kw...)
75+
d = init_module(false, kw...)[1]
76+
gmt2kml_helper(cmd0, arg1, d)
77+
end
78+
function gmt2kml_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
7779

7880
cmd, = parse_common_opts(d, "", [:R :V_params :bi :di :e :f :h :i :yx])
7981
cmd = parse_these_opts(cmd, d, [[:A :altitude_mode], [:D :descript], [:E :extrude], [:F :feature_type], [:G :fill],

src/gmtconnect.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,12 @@ Parameters
2626
2727
To see the full documentation type: ``@? gmtconnect``
2828
"""
29-
function gmtconnect(cmd0::String="", arg1=nothing, arg2=nothing; kwargs...)
29+
function gmtconnect(cmd0::String="", arg1=nothing, arg2=nothing; kw...)
30+
d = init_module(false, kw...)[1]
31+
gmtconnect(cmd0, arg1, d)
32+
end
33+
function gmtconnect(cmd0::String, arg1, d::Dict{Symbol, Any})
3034

31-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
3235
cmd, = parse_common_opts(d, "", [:V_params :b :d :e :f :g :h :i :o :yx])
3336
cmd = parse_these_opts(cmd, d, [[:C :closed], [:D :dump], [:L :links :linkfile], [:Q :list :listfile], [:T :tolerance]])
3437

src/gmtregress.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ Parameters
4747
- $(opt_w)
4848
- $(opt_swap_xy)
4949
"""
50-
function regress(cmd0::String="", arg1=nothing; kwargs...)
50+
function regress(cmd0::String="", arg1=nothing; kw...)
51+
d = init_module(false, kw...)[1]
52+
regress(cmd0, arg1, d)
53+
end
54+
function regress(cmd0::String, arg1, d::Dict{Symbol, Any})
5155

52-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
5356
cmd, = parse_common_opts(d, "", [:V_params :b :d :e :g :h :i :o :w :yx])
5457
cmd = parse_these_opts(cmd, d, [[:A :all_slopes], [:C :ci :cl :confidence_level], [:E :regression_type], [:N :norm],
5558
[:F :column_combination], [:S :restrict], [:T :equi_space], [:W :weights :weighted]])

src/gmtselect.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@ Parameters
6060
- $(opt_w)
6161
- $(opt_swap_xy)
6262
"""
63-
function gmtselect(cmd0::String="", arg1=nothing, arg2=nothing, arg3=nothing, arg4=nothing; kwargs...)
64-
65-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
63+
function gmtselect(cmd0::String="", arg1=nothing, arg2=nothing, arg3=nothing, arg4=nothing; kw...)
64+
d = init_module(false, kw...)[1]
65+
gmtselect(cmd0, arg1, arg2, arg3, arg4, d)
66+
end
67+
function gmtselect(cmd0::String, arg1, arg2, arg3, arg4, d::Dict{Symbol, Any})
6668

6769
cmd::String = parse_common_opts(d, "", [:R :V_params :b :d :e :f :g :h :i :o :w :yx])[1]
6870
cmd = parse_these_opts(cmd, d, [[:A :area], [:D :res :resolution], [:E :boundary],

src/gmtset.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ Parameters
2121
2222
gmtset(FONT_ANNOT_PRIMARY="12p,Helvetica", MAP_GRID_CROSS_SIZE_PRIMARY=0.25)
2323
"""
24-
function gmtset(; kwargs...)
25-
26-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
24+
function gmtset(; kw...)
25+
d = init_module(false, kw...)[1]
26+
gmtset(d)
27+
end
28+
function gmtset(d::Dict{Symbol, Any})
2729

2830
cmd = parse_V(d, "")
2931
cmd = add_opt(d, cmd, "D", [:D :units])

src/gmtsimplify.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ Parameters
2525
- $(opt_o)
2626
- $(opt_swap_xy)
2727
"""
28-
gmtsimplify(cmd0::String; kwargs...) = gmtsimplify_helper(cmd0, nothing; kwargs...)
29-
gmtsimplify(arg1; kwargs...) = gmtsimplify_helper("", arg1; kwargs...)
28+
gmtsimplify(cmd0::String; kw...) = gmtsimplify_helper(cmd0, nothing; kw...)
29+
gmtsimplify(arg1; kw...) = gmtsimplify_helper("", arg1; kw...)
3030

3131
# ---------------------------------------------------------------------------------------------------
32-
function gmtsimplify_helper(cmd0::String, arg1; kwargs...)
33-
34-
d = init_module(false, kwargs...)[1] # Also checks if the user wants ONLY the HELP mode
32+
function gmtsimplify_helper(cmd0::String, arg1; kw...)
33+
d = init_module(false, kw...)[1]
34+
gmtsimplify_helper(cmd0, arg1, d)
35+
end
36+
function gmtsimplify_helper(cmd0::String, arg1, d::Dict{Symbol, Any})
3537

3638
cmd, = parse_common_opts(d, "", [:V_params :b :d :e :f :g :h :i :o :yx])
3739
cmd = add_opt(d, cmd, "T", [:T :tol :tolerance])

0 commit comments

Comments
 (0)