@@ -10,6 +10,8 @@ open Learnocaml_data
10
10
open Lwt.Infix
11
11
module Api = Learnocaml_api
12
12
13
+ module ES = Exercise. Status
14
+
13
15
open Cmdliner
14
16
open Arg
15
17
@@ -37,6 +39,50 @@ let url_conv =
37
39
(fun fmt t -> Format. pp_print_string fmt (Token. to_string t))
38
40
)
39
41
42
+ module Args_server = struct
43
+ type t = {
44
+ server_url : Uri .t option ;
45
+ local : bool ;
46
+ }
47
+
48
+ let server_url =
49
+ value & opt (some url_conv) None &
50
+ info [" s" ;" server" ] ~docv: " URL" ~doc:
51
+ " The URL of the learn-ocaml server."
52
+ ~env: (Term. env_info " LEARNOCAML_SERVER" ~doc:
53
+ " Sets the learn-ocaml server URL. Overridden by $(b,--server)." )
54
+ let local =
55
+ value & flag & info [" local" ] ~doc:
56
+ " Use a configuration file local to the current directory, rather \
57
+ than user-wide."
58
+
59
+ let apply server_url local =
60
+ {server_url; local}
61
+
62
+ let term =
63
+ Term. (const apply $ server_url $ local)
64
+
65
+ let term_server =
66
+ Term. (const (fun x -> x) $ server_url)
67
+ end
68
+
69
+ module Args_logout = struct
70
+ type t = {
71
+ local : bool ;
72
+ }
73
+
74
+ let local =
75
+ value & flag & info [" local" ] ~doc:
76
+ " Use a configuration file local to the current directory, rather \
77
+ than user-wide."
78
+
79
+ let apply local =
80
+ {local}
81
+
82
+ let term =
83
+ Term. (const apply $ local)
84
+ end
85
+
40
86
module Args_global = struct
41
87
type t = {
42
88
server_url : Uri .t option ;
@@ -93,6 +139,8 @@ module Args_create_token = struct
93
139
let term = Term. (const apply $ nickname $ secret)
94
140
end
95
141
142
+
143
+
96
144
module Args_create_user = struct
97
145
type t = {
98
146
email : string ;
@@ -675,6 +723,37 @@ let get_config_o ?save_back ?(allow_static=false) o =
675
723
let open Args_global in
676
724
get_config ~local: o.local ?save_back ~allow_static o.server_url o.token
677
725
726
+ let get_config_option_server ?local ?(save_back =false ) ?(allow_static =false ) server_opt =
727
+ match ConfigFile. path ?local () with
728
+ | Some f ->
729
+ ConfigFile. read f >> = fun c ->
730
+ let c = match server_opt with
731
+ | Some server -> { c with ConfigFile. server }
732
+ | None -> c
733
+ in
734
+ check_server_version ~allow_static c.ConfigFile. server
735
+ >> = fun _ ->
736
+ (
737
+ if save_back
738
+ then
739
+ ConfigFile. write f c > |= fun () ->
740
+ Printf. eprintf " Configuration written to %s\n %!" f
741
+ else
742
+ Lwt. return_unit
743
+ )
744
+ > |= fun () -> Some c
745
+ | None -> Lwt. return_none
746
+
747
+ let get_config_server ?local ?(save_back =false ) ?(allow_static =false ) server_opt =
748
+ get_config_option_server ?local ~save_back ~allow_static server_opt
749
+ >> = function
750
+ | Some c -> Lwt. return c
751
+ | None -> Lwt. fail_with " No config file found. Please do `learn-ocaml-client init`"
752
+
753
+ let get_config_o_server ?save_back ?(allow_static =false ) o =
754
+ let open Args_server in
755
+ get_config_server ~local: o.local ?save_back ~allow_static o.server_url
756
+
678
757
module Init = struct
679
758
open Args_global
680
759
open Args_create_token
@@ -719,12 +798,12 @@ module Init = struct
719
798
end
720
799
721
800
module Init_server = struct
722
- open Args_global
801
+ open Args_server
723
802
724
- let init_server global_args =
725
- let path = if global_args .local then ConfigFile. local_path else ConfigFile. user_path in
803
+ let init_server server_args =
804
+ let path = if server_args .local then ConfigFile. local_path else ConfigFile. user_path in
726
805
let get_server () =
727
- match global_args .server_url with
806
+ match server_args .server_url with
728
807
| None -> Lwt. fail_with " You must provide a server."
729
808
| Some s -> Lwt. return s
730
809
in
@@ -739,17 +818,17 @@ module Init_server = struct
739
818
let cmd =
740
819
Term. (
741
820
const (fun go -> Pervasives. exit (Lwt_main. run (init_server go)))
742
- $ Args_global . term),
821
+ $ Args_server . term),
743
822
Term. info ~man
744
823
~doc: " Initialize the configuration file."
745
824
" init-server"
746
825
end
747
826
748
827
module Logout = struct
749
- open Args_global
828
+ open Args_logout
750
829
751
- let logout global_args =
752
- let path = if global_args .local then ConfigFile. local_path else ConfigFile. user_path in
830
+ let logout logout_args =
831
+ let path = if logout_args .local then ConfigFile. local_path else ConfigFile. user_path in
753
832
let get_server () = Lwt. return Uri. empty
754
833
in
755
834
get_server () >> = fun server ->
@@ -763,7 +842,7 @@ module Logout = struct
763
842
let cmd =
764
843
Term. (
765
844
const (fun go -> Pervasives. exit (Lwt_main. run (logout go)))
766
- $ Args_global . term),
845
+ $ Args_logout . term),
767
846
Term. info ~man
768
847
~doc: " delete current configuration file."
769
848
" logout"
@@ -1141,9 +1220,11 @@ module Exercise_list = struct
1141
1220
end
1142
1221
1143
1222
module Server_config = struct
1223
+ open Args_server
1224
+
1144
1225
let doc = " Get a structured json containing an information about the use_password compatibility"
1145
1226
1146
- let server_config o = get_config_o ~allow_static: true o
1227
+ let server_config o = get_config_o_server ~allow_static: true o
1147
1228
>> = fun {ConfigFile. server;_} ->
1148
1229
fetch server (Learnocaml_api. Server_config () )
1149
1230
>> = (fun isPassword ->
@@ -1162,13 +1243,25 @@ module Server_config = struct
1162
1243
let man = man doc
1163
1244
1164
1245
let cmd =
1165
- use_global server_config,
1166
- Term. info ~man ~doc: doc " server-config"
1246
+ Term. (
1247
+ const (fun go -> Pervasives. exit (Lwt_main. run (server_config go)))
1248
+ $ Args_server. term),
1249
+ Term. info ~man
1250
+ ~doc: doc
1251
+ " server-config"
1167
1252
end
1168
1253
1169
1254
module Exercise_score = struct
1170
1255
let doc = " Get informations about scores of exercises"
1171
1256
1257
+ let status_map = ref SMap. empty
1258
+
1259
+ let open_exercises =
1260
+ SMap. fold (fun ex st acc ->
1261
+ if ES. (st.assignments.default = Open ) then ex::acc else acc)
1262
+ ! status_map []
1263
+ |> List. rev
1264
+
1172
1265
let exercise_score _ = Lwt. return 0
1173
1266
1174
1267
let man = man doc
0 commit comments