@@ -27,29 +27,35 @@ struct Process
27
27
experimental:: Union{Nothing,Bool}
28
28
end
29
29
StructTypes. StructType (:: Type{Process} ) = StructTypes. Struct ()
30
- function (process:: Process )(args... )
31
- params = get_parameters (process. parameters)
32
- length (args) == length (params) || throw (ArgumentError (" Number of arguments does not match for process $(process. id) " ))
33
- argument_dict = Dict {Symbol,Any} ()
34
- for i in 1 : length (args)
35
- argname, argtype = params[i]
36
- args[i] isa argtype || throw (ArgumentError (" Type of argument number $i does not match, expected $argtype but got $(typeof (args[i])) " ))
37
- argument_dict[argname] = args[i]
30
+
31
+ function (process:: Process )(args... ; kwargs... )
32
+ required_args = get_parameters (process. parameters, :required )
33
+
34
+ length (required_args) == length (args) || error (" Must provide $(length (required_args)) positional arguments" )
35
+
36
+ args_d = Dict {Symbol,Any} (zip (map (x -> x. first, required_args), args))
37
+ merge! (args_d, Dict (kwargs))
38
+
39
+ if isnothing (args_d)
40
+ args_d = Dict {Symbol,Any} ()
38
41
end
39
- ProcessCall (" $(process. id) " , argument_dict )
42
+ ProcessCall (" $(process. id) " , args_d )
40
43
end
44
+
41
45
function Docs. getdoc (process:: Process )
42
- arguments = get_parameters (process. parameters)
43
- args_str = join ([" $(k) ::$(v) " for (k, v) in arguments ], " , " )
44
- docs = """ $(process. id) ($(args_str) )
46
+ args_str = join ([ " $(k) :: $(v) " for (k, v) in get_parameters (process. parameters, :required )], " , " )
47
+ kwargs_str = join ([" $(k) ::$(v) " for (k, v) in get_parameters (process . parameters, :optional ) ], " , " )
48
+ docs = """ $(process. id) ($(args_str) ; $(kwargs_str) )
45
49
$(process. description)
46
50
"""
47
51
Markdown. parse (docs)
48
52
end
49
53
Base. Docs. doc (p:: Process , :: Type = Union{}) = Base. Docs. getdoc (p)
50
54
51
55
function Base. show (io:: IO , :: MIME"text/plain" , p:: Process )
52
- print (io, " $(p. id) ($(join ([x. name for x in p. parameters], " , " )) ): $(p. summary) " )
56
+ args_str = join ([" $(k) ::$(v) " for (k, v) in get_parameters (p. parameters, :required )], " , " )
57
+ kwargs_str = join ([" $(k) ::$(v) " for (k, v) in get_parameters (p. parameters, :optional )], " , " )
58
+ print (io, " $(p. id) ($(args_str) ; $(kwargs_str) ): $(p. summary) " )
53
59
end
54
60
55
61
# root e.g. https://earthengine.openeo.org/v1.0/processes
@@ -76,7 +82,6 @@ mutable struct ProcessCall <: AbstractProcessCall
76
82
const arguments:: Dict{Symbol,Any}
77
83
result:: Bool
78
84
end
79
- ProcessCall (id, process_id, arguments) = ProcessCall (id, process_id, arguments, false )
80
85
StructTypes. StructType (:: Type{ProcessCall} ) = StructTypes. Mutable ()
81
86
StructTypes. excludes (:: Type{ProcessCall} ) = (:id ,)
82
87
@@ -112,7 +117,7 @@ function Base.show(io::IO, ::MIME"text/plain", p::ProcessCall)
112
117
pretty_print (io, Dict (:result => p. result))
113
118
end
114
119
115
- function get_parameters (parameters)
120
+ function get_parameters (parameters, keep = :all )
116
121
# openEO type string to Julia type
117
122
julia_types_map = Dict (
118
123
" string" => String,
@@ -145,7 +150,9 @@ function get_parameters(parameters)
145
150
julia_types = [get (julia_types_map, t, String) for t in types]
146
151
julia_type = Union{julia_types... }
147
152
148
- push! (res, name => julia_type)
153
+ if keep == :all || (keep == :optional && p. optional == true ) || (keep == :required && isnothing (p. optional))
154
+ push! (res, name => julia_type)
155
+ end
149
156
end
150
157
return res
151
158
end
0 commit comments