1:- module(
2 task,
3 [
4 run_task/1, 5 run_task/2, 6 run_task/3 7 ]
8). 9:- reexport(library(debug)).
15:- use_module(library(ansi_term)). 16
17:- use_module(library(file_ext)). 18
19:- meta_predicate
20 run_task(0),
21 run_task(0, +),
22 run_task(0, +, +).
34run_task(Mod:Goal_0) :-
35 term_string(Goal_0, Format),
36 run_task(Mod:Goal_0, Format).
37
38
39run_task(Goal_0, Format) :-
40 run_task(Goal_0, Format, []).
41
42
43run_task(Mod:Goal_0, Format, Args) :-
44 format(atom(Local), "~w", [Goal_0]),
45 file_name_extension(Local, task, File),
46 ( exists_file(File)
47 -> ansi_format([fg(green)], "Task was already performed earlier: ~a\n",
48 [Local])
49 ; get_time(Start),
50 format(Format, Args),
51 ( catch(Mod:Goal_0, E, true)
52 -> ( var(E)
53 -> get_time(End),
54 Delta is End - Start,
55 ansi_format([fg(green)], "~`.t success (~2f sec.)~72|", [Delta])
56 ; message_to_string(E, S),
57 ansi_format([fg(red)], "~`.t ERROR: ~w~72|", [S])
58 )
59 ; ansi_format([fg(red)], "~`.t ERROR: (failed)~72|", [])
60 ),
61 nl,
62 touch(File)
63 )
Support for running tasks
*/