commandline.pl 1.13 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1
2
3
4
5
6
7
:- module(
  commandline,
  [
    do_arguments/0
  ]
).

Thierry Martinez's avatar
Thierry Martinez committed
8

Thierry Martinez's avatar
Thierry Martinez committed
9
10
11
12
do_arguments :-
  current_prolog_flag(argv, Argv),
  do_arguments(Argv).

Thierry Martinez's avatar
Thierry Martinez committed
13

Thierry Martinez's avatar
Thierry Martinez committed
14
15
:- dynamic(file/1).

Thierry Martinez's avatar
Thierry Martinez committed
16

Thierry Martinez's avatar
Thierry Martinez committed
17
18
19
20
21
do_arguments(Argv) :-
  retractall(file(_)),
  parse_arguments(Argv),
  load_files.

Thierry Martinez's avatar
Thierry Martinez committed
22

Thierry Martinez's avatar
Thierry Martinez committed
23
24
25
26
27
28
29
30
load_files :-
  \+ (
    file(File),
    \+ (
      load(File)
    )
  ).

Thierry Martinez's avatar
Thierry Martinez committed
31

Thierry Martinez's avatar
Thierry Martinez committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
parse_arguments([]).

parse_arguments([Arg | Argv]) :-
  (
    Arg = '--'
  ->
    add_files(Argv)
  ;
    atom_concat('--', _, Arg)
  ->
    (
      option(_, Arg, Argv, ArgTail)
    ->
      parse_arguments(ArgTail)
    ;
      throw(error(unknown_option(Arg)))
    )
  ;
    add_file(Arg),
    parse_arguments(Argv)
  ).


Thierry Martinez's avatar
Thierry Martinez committed
55
option('', '--trace', Arg, Arg) :-
Thierry Martinez's avatar
Thierry Martinez committed
56
57
58
  leash(-all),
  trace.

Thierry Martinez's avatar
Thierry Martinez committed
59
60
61
62
option('', '--generate-doc', Arg, Arg) :-
  generate_doc,
  quit.

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
63
64
65
option('', '--version', Arg, Arg) :-
   quit.

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
66
67
68
69
70
71
72
option('', '--jupyter', Arg, Arg) :-
  set_counter(plot_png, 0),
  set_counter(graph_svg, 0),
  set_plot_driver(gnu_plot_png),
  set_image_viewer_driver(img_tag),
  set_draw_graph_driver(graph_svg).

SOLIMAN Sylvain's avatar
SOLIMAN Sylvain committed
73

Thierry Martinez's avatar
Thierry Martinez committed
74
75
76
77
78
79
80
81
add_files(Files) :-
  \+ (
    member(File, Files),
    \+ (
      add_file(File)
    )
  ).

Thierry Martinez's avatar
Thierry Martinez committed
82

Thierry Martinez's avatar
Thierry Martinez committed
83
84
add_file(File) :-
  assertz(file(File)).