|
@@ -42,7 +42,7 @@ open Command;;
|
|
|
|
|
|
(* Type to return result of the work with common arguments *)
|
|
(* Type to return result of the work with common arguments *)
|
|
type return_arg = {
|
|
type return_arg = {
|
|
- rc : Settings_t.rc_file;
|
|
|
|
|
|
+ rc : Settings_t.rc_file Lazy.t;
|
|
}
|
|
}
|
|
|
|
|
|
(* A set of default arguments, usable with most of the commands *)
|
|
(* A set of default arguments, usable with most of the commands *)
|
|
@@ -54,20 +54,31 @@ let shared_params =
|
|
Const.verbosity := verbosity;
|
|
Const.verbosity := verbosity;
|
|
(* Do not use color *)
|
|
(* Do not use color *)
|
|
Const.no_color := no_color || !Const.no_color;
|
|
Const.no_color := no_color || !Const.no_color;
|
|
- (* Use given rc file, should run the nth argument if present *)
|
|
|
|
- Const.rc_file := (Lazy.return rc_file_name);
|
|
|
|
|
|
+ (* Use given rc file, preserving lazyness, since Const.rc_file is not
|
|
|
|
+ * yet evaluated *)
|
|
|
|
+ Const.rc_file :=
|
|
|
|
+ Option.value_map ~f:(fun rfn -> Lazy.return rfn)
|
|
|
|
+ ~default:!Const.rc_file rc_file_name
|
|
|
|
+ ;
|
|
(* Active signal handling *)
|
|
(* Active signal handling *)
|
|
if handle_signal then
|
|
if handle_signal then
|
|
Signals.handle ();
|
|
Signals.handle ();
|
|
|
|
|
|
(* Debugging *)
|
|
(* Debugging *)
|
|
- Messages.debug (sprintf "Verbosity set to %i" !Const.verbosity);
|
|
|
|
- Messages.debug (sprintf "Color %s" (match !Const.no_color with true -> "off" | false -> "on"));
|
|
|
|
- Messages.debug (sprintf "Configuration file is %s" (Lazy.force !Const.rc_file));
|
|
|
|
- Messages.debug (sprintf "Tmp file is %s" Const.tmp_file);
|
|
|
|
|
|
+ let d = Messages.debug in
|
|
|
|
+ d (sprintf "Verbosity set to %i" !Const.verbosity);
|
|
|
|
+ d (sprintf "Color %s" (match !Const.no_color with true -> "off" | false -> "on"));
|
|
|
|
+ begin
|
|
|
|
+ match Option.try_with (fun () -> Lazy.force !Const.rc_file) with
|
|
|
|
+ | None -> d "Configuration file will fail if used";
|
|
|
|
+ | Some rc -> d (sprintf "Configuration file is %s" rc);
|
|
|
|
+ end;
|
|
|
|
+ d (sprintf "Tmp file is %s" Const.tmp_file);
|
|
|
|
|
|
(* Obtain data from rc_file *)
|
|
(* Obtain data from rc_file *)
|
|
- let rc_content = File_com.init_rc () in
|
|
|
|
|
|
+ d "Reading rc_file...";
|
|
|
|
+ let rc_content = lazy (File_com.init_rc ()) in
|
|
|
|
+ d "Read rc_file";
|
|
{ rc = rc_content } (* We use type for futur use *)
|
|
{ rc = rc_content } (* We use type for futur use *)
|
|
)
|
|
)
|
|
(* Flag to set verbosity level *)
|
|
(* Flag to set verbosity level *)
|
|
@@ -80,7 +91,7 @@ let shared_params =
|
|
~aliases:["-no-color"]
|
|
~aliases:["-no-color"]
|
|
~doc:" Use this flag to disable color usage."
|
|
~doc:" Use this flag to disable color usage."
|
|
(* Flag to use different rc file *)
|
|
(* Flag to use different rc file *)
|
|
- <*> flag "-c" (optional_with_default (Lazy.force !Const.rc_file) file)
|
|
|
|
|
|
+ <*> flag "-c" (optional file)
|
|
~aliases:["--rc" ; "-rc"]
|
|
~aliases:["--rc" ; "-rc"]
|
|
~doc:"file Read configuration from the given file and continue parsing."
|
|
~doc:"file Read configuration from the given file and continue parsing."
|
|
(* Flag to handle signals *)
|
|
(* Flag to handle signals *)
|
|
@@ -113,6 +124,7 @@ let reset =
|
|
* cmd = Some n
|
|
* cmd = Some n
|
|
* cmd: number of the command to be reseted
|
|
* cmd: number of the command to be reseted
|
|
* num: number to reset *)
|
|
* num: number to reset *)
|
|
|
|
+ let rc = Lazy.force rc in
|
|
match ( num, cmd ) with
|
|
match ( num, cmd ) with
|
|
| ( num, Some cmd ) -> Tmp_file.reset_cmd ~rc num cmd
|
|
| ( num, Some cmd ) -> Tmp_file.reset_cmd ~rc num cmd
|
|
| ( num, None ) -> Tmp_file.reset2num ~rc num
|
|
| ( num, None ) -> Tmp_file.reset2num ~rc num
|
|
@@ -138,14 +150,13 @@ let list =
|
|
Spec.(
|
|
Spec.(
|
|
empty
|
|
empty
|
|
+> shared_params
|
|
+> shared_params
|
|
- +> flag "--el" (optional int)
|
|
|
|
|
|
+ +> flag "-l" (optional int)
|
|
|
|
+ ~aliases:[ "--length" ; "-length" ; "--elength" ; "-elength" ]
|
|
~doc:" Max length of displayed entries, 0 keeps as-is"
|
|
~doc:" Max length of displayed entries, 0 keeps as-is"
|
|
)
|
|
)
|
|
- (fun { rc } length () ->
|
|
|
|
- (* XXX A match case to deal with optionnal argument is tricky *)
|
|
|
|
- match length with
|
|
|
|
- | None -> List_rc.run ~rc ()
|
|
|
|
- | Some l -> List_rc.run ~rc ~elength:l ())
|
|
|
|
|
|
+ (fun { rc } elength () ->
|
|
|
|
+ let rc = Lazy.force rc in
|
|
|
|
+ List_rc.run ~rc ?elength ())
|
|
;;
|
|
;;
|
|
|
|
|
|
(* To clean-up rc file *)
|
|
(* To clean-up rc file *)
|
|
@@ -158,6 +169,7 @@ let clean =
|
|
+> shared_params
|
|
+> shared_params
|
|
)
|
|
)
|
|
(fun { rc } () ->
|
|
(fun { rc } () ->
|
|
|
|
+ let rc = Lazy.force rc in
|
|
Clean_command.run ~rc ()
|
|
Clean_command.run ~rc ()
|
|
)
|
|
)
|
|
;;
|
|
;;
|
|
@@ -173,6 +185,7 @@ let add =
|
|
+> anon (maybe ("number" %: int))
|
|
+> anon (maybe ("number" %: int))
|
|
)
|
|
)
|
|
(fun { rc } num_cmd () ->
|
|
(fun { rc } num_cmd () ->
|
|
|
|
+ let rc = Lazy.force rc in
|
|
Add_command.run ~rc num_cmd
|
|
Add_command.run ~rc num_cmd
|
|
)
|
|
)
|
|
;;
|
|
;;
|
|
@@ -188,6 +201,7 @@ let delete =
|
|
+> anon (maybe ("command_number" %: int))
|
|
+> anon (maybe ("command_number" %: int))
|
|
)
|
|
)
|
|
(fun { rc } num_cmd () ->
|
|
(fun { rc } num_cmd () ->
|
|
|
|
+ let rc = Lazy.force rc in
|
|
(*Tmp_file.reset ~rc reset_cmd 0)*)
|
|
(*Tmp_file.reset ~rc reset_cmd 0)*)
|
|
Remove_command.run ~rc num_cmd)
|
|
Remove_command.run ~rc num_cmd)
|
|
;;
|
|
;;
|
|
@@ -201,6 +215,7 @@ let state =
|
|
+> shared_params
|
|
+> shared_params
|
|
)
|
|
)
|
|
(fun { rc } () ->
|
|
(fun { rc } () ->
|
|
|
|
+ let rc = Lazy.force rc in
|
|
State.print_current ~rc ())
|
|
State.print_current ~rc ())
|
|
;;
|
|
;;
|
|
|
|
|
|
@@ -217,6 +232,7 @@ let edit =
|
|
+> anon (maybe ("command_number" %: int))
|
|
+> anon (maybe ("command_number" %: int))
|
|
)
|
|
)
|
|
(fun { rc } n () ->
|
|
(fun { rc } n () ->
|
|
|
|
+ let rc = Lazy.force rc in
|
|
let position = Option.value
|
|
let position = Option.value
|
|
~default:(List.length (rc.Settings_t.progs) - 1) n
|
|
~default:(List.length (rc.Settings_t.progs) - 1) n
|
|
in
|
|
in
|
|
@@ -250,6 +266,7 @@ let default =
|
|
+> anon (maybe ("command_number" %: int))
|
|
+> anon (maybe ("command_number" %: int))
|
|
)
|
|
)
|
|
(fun { rc } n () ->
|
|
(fun { rc } n () ->
|
|
|
|
+ let rc = Lazy.force rc in
|
|
Default.run ~rc n)
|
|
Default.run ~rc n)
|
|
|
|
|
|
let run ~version ~build_info () =
|
|
let run ~version ~build_info () =
|