64
64
import sys
65
65
from typing import TYPE_CHECKING , Iterable , List , Tuple
66
66
67
+ from metomi .isodatetime .exceptions import ISO8601SyntaxError
68
+ from metomi .isodatetime .parsers import DurationParser
69
+
67
70
from cylc .flow import LOG
68
71
from cylc .flow .clean import init_clean , get_contained_workflows
69
72
from cylc .flow .exceptions import CylcError , InputError
@@ -140,6 +143,24 @@ def get_option_parser():
140
143
CleanOptions = Options (get_option_parser ())
141
144
142
145
146
+ def parse_timeout (opts : 'Values' ) -> None :
147
+ """Parse timeout as ISO 8601 duration or number of seconds."""
148
+ if opts .remote_timeout :
149
+ try :
150
+ timeout = int (
151
+ DurationParser ().parse (opts .remote_timeout ).get_seconds ()
152
+ )
153
+ except ISO8601SyntaxError :
154
+ try :
155
+ timeout = int (opts .remote_timeout )
156
+ except ValueError :
157
+ raise InputError (
158
+ f"Invalid timeout: { opts .remote_timeout } . Must be "
159
+ "an ISO 8601 duration or number of seconds."
160
+ )
161
+ opts .remote_timeout = str (timeout )
162
+
163
+
143
164
def prompt (workflows : Iterable [str ]) -> None :
144
165
"""Ask user if they want to clean the given set of workflows."""
145
166
print ("Would clean the following workflows:" )
@@ -220,7 +241,15 @@ async def run(*ids: str, opts: 'Values') -> None:
220
241
221
242
222
243
@cli_function (get_option_parser )
223
- def main (_ , opts : 'Values' , * ids : str ):
244
+ def main (_parser , opts : 'Values' , * ids : str ):
245
+ _main (opts , * ids )
246
+
247
+
248
+ def _main (opts : 'Values' , * ids : str ):
249
+ """Run the clean command.
250
+
251
+ This is a separate function for ease of testing.
252
+ """
224
253
if cylc .flow .flags .verbosity < 2 :
225
254
set_timestamps (LOG , False )
226
255
@@ -229,4 +258,6 @@ def main(_, opts: 'Values', *ids: str):
229
258
"--local and --remote options are mutually exclusive"
230
259
)
231
260
261
+ parse_timeout (opts )
262
+
232
263
asyncio .run (run (* ids , opts = opts ))
0 commit comments