@@ -44,8 +44,20 @@ def convert(self, value, param, ctx):
44
44
self .fail (f"{ value !r} is not splittable" , param , ctx )
45
45
46
46
47
+ class KeyValueParamType (click .ParamType ):
48
+ name = "key_value"
49
+
50
+ def convert (self , value , param , ctx ):
51
+ try :
52
+ return tuple (value .split ("=" , 1 )) if value else ()
53
+ except AttributeError :
54
+ self .fail (f"{ value !r} is not splittable" , param , ctx )
55
+
56
+
47
57
CSV = CSVParamType ()
58
+ KeyValue = KeyValueParamType ()
48
59
OPTION_CRATE_PATH = click .option ('-c' , '--crate-dir' , type = click .Path (), default = os .getcwd )
60
+ OPTION_PROPS = click .option ('-P' , '--property' , type = KeyValue , multiple = True , metavar = "KEY=VALUE" )
49
61
50
62
51
63
@click .group ()
@@ -72,38 +84,41 @@ def add():
72
84
@add .command ()
73
85
@click .argument ('path' , type = click .Path (exists = True , dir_okay = False ))
74
86
@OPTION_CRATE_PATH
75
- def file (crate_dir , path ):
87
+ @OPTION_PROPS
88
+ def file (crate_dir , path , property ):
76
89
crate = ROCrate (crate_dir , init = False , gen_preview = False )
77
90
source = Path (path ).resolve (strict = True )
78
91
try :
79
92
dest_path = source .relative_to (crate_dir )
80
93
except ValueError :
81
94
# For now, only support adding an existing file to the metadata
82
95
raise ValueError (f"{ source } is not in the crate dir { crate_dir } " )
83
- crate .add_file (source , dest_path )
96
+ crate .add_file (source , dest_path , properties = dict ( property ) )
84
97
crate .metadata .write (crate_dir )
85
98
86
99
87
100
@add .command ()
88
101
@click .argument ('path' , type = click .Path (exists = True , file_okay = False ))
89
102
@OPTION_CRATE_PATH
90
- def dataset (crate_dir , path ):
103
+ @OPTION_PROPS
104
+ def dataset (crate_dir , path , property ):
91
105
crate = ROCrate (crate_dir , init = False , gen_preview = False )
92
106
source = Path (path ).resolve (strict = True )
93
107
try :
94
108
dest_path = source .relative_to (crate_dir )
95
109
except ValueError :
96
110
# For now, only support adding an existing directory to the metadata
97
111
raise ValueError (f"{ source } is not in the crate dir { crate_dir } " )
98
- crate .add_dataset (source , dest_path )
112
+ crate .add_dataset (source , dest_path , properties = dict ( property ) )
99
113
crate .metadata .write (crate_dir )
100
114
101
115
102
116
@add .command ()
103
117
@click .argument ('path' , type = click .Path (exists = True ))
104
118
@click .option ('-l' , '--language' , type = click .Choice (LANG_CHOICES ), default = "cwl" )
105
119
@OPTION_CRATE_PATH
106
- def workflow (crate_dir , path , language ):
120
+ @OPTION_PROPS
121
+ def workflow (crate_dir , path , language , property ):
107
122
crate = ROCrate (crate_dir , init = False , gen_preview = False )
108
123
source = Path (path ).resolve (strict = True )
109
124
try :
@@ -112,7 +127,7 @@ def workflow(crate_dir, path, language):
112
127
# For now, only support marking an existing file as a workflow
113
128
raise ValueError (f"{ source } is not in the crate dir { crate_dir } " )
114
129
# TODO: add command options for main and gen_cwl
115
- crate .add_workflow (source , dest_path , main = True , lang = language , gen_cwl = False )
130
+ crate .add_workflow (source , dest_path , main = True , lang = language , gen_cwl = False , properties = dict ( property ) )
116
131
crate .metadata .write (crate_dir )
117
132
118
133
@@ -121,9 +136,13 @@ def workflow(crate_dir, path, language):
121
136
@click .option ('-n' , '--name' )
122
137
@click .option ('-m' , '--main-entity' )
123
138
@OPTION_CRATE_PATH
124
- def suite (crate_dir , identifier , name , main_entity ):
139
+ @OPTION_PROPS
140
+ def suite (crate_dir , identifier , name , main_entity , property ):
125
141
crate = ROCrate (crate_dir , init = False , gen_preview = False )
126
- suite = crate .add_test_suite (identifier = add_hash (identifier ), name = name , main_entity = main_entity )
142
+ suite = crate .add_test_suite (
143
+ identifier = add_hash (identifier ), name = name , main_entity = main_entity ,
144
+ properties = dict (property )
145
+ )
127
146
crate .metadata .write (crate_dir )
128
147
print (suite .id )
129
148
@@ -136,11 +155,12 @@ def suite(crate_dir, identifier, name, main_entity):
136
155
@click .option ('-i' , '--identifier' )
137
156
@click .option ('-n' , '--name' )
138
157
@OPTION_CRATE_PATH
139
- def instance (crate_dir , suite , url , resource , service , identifier , name ):
158
+ @OPTION_PROPS
159
+ def instance (crate_dir , suite , url , resource , service , identifier , name , property ):
140
160
crate = ROCrate (crate_dir , init = False , gen_preview = False )
141
161
instance_ = crate .add_test_instance (
142
162
add_hash (suite ), url , resource = resource , service = service ,
143
- identifier = add_hash (identifier ), name = name
163
+ identifier = add_hash (identifier ), name = name , properties = dict ( property )
144
164
)
145
165
crate .metadata .write (crate_dir )
146
166
print (instance_ .id )
@@ -152,7 +172,8 @@ def instance(crate_dir, suite, url, resource, service, identifier, name):
152
172
@click .option ('-e' , '--engine' , type = click .Choice (ENGINE_CHOICES ), default = "planemo" )
153
173
@click .option ('-v' , '--engine-version' )
154
174
@OPTION_CRATE_PATH
155
- def definition (crate_dir , suite , path , engine , engine_version ):
175
+ @OPTION_PROPS
176
+ def definition (crate_dir , suite , path , engine , engine_version , property ):
156
177
crate = ROCrate (crate_dir , init = False , gen_preview = False )
157
178
source = Path (path ).resolve (strict = True )
158
179
try :
@@ -162,7 +183,7 @@ def definition(crate_dir, suite, path, engine, engine_version):
162
183
raise ValueError (f"{ source } is not in the crate dir { crate_dir } " )
163
184
crate .add_test_definition (
164
185
add_hash (suite ), source = source , dest_path = dest_path , engine = engine ,
165
- engine_version = engine_version
186
+ engine_version = engine_version , properties = dict ( property )
166
187
)
167
188
crate .metadata .write (crate_dir )
168
189
0 commit comments