Parcourir la source

Improve -l

 - Improve “-l”: now display a “*” next to current state.
Leo il y a 10 ans
Parent
commit
b68197f1b8
7 fichiers modifiés avec 247 ajouts et 287 suppressions
  1. 1 0
      CHANGELOG.md
  2. 2 2
      configure
  3. 52 66
      myocamlbuild.ml
  4. 174 210
      setup.ml
  5. 2 2
      src/command_def.ml
  6. 7 4
      src/list_rc.ml
  7. 9 3
      src/state.ml

+ 1 - 0
CHANGELOG.md

@@ -3,6 +3,7 @@
 ## v0.2.1
  + Add new command line option:
    + “-c file” allow to read configuration from custom file.
+ + Improve “-l”: now display a “\*” next to current state.
 
 ## v0.2.0
  + Add new command line option.

+ 2 - 2
configure

@@ -1,7 +1,7 @@
 #!/bin/sh
 
 # OASIS_START
-# DO NOT EDIT (digest: 6f7b8221311e800a7093dc3b793f67ca)
+# DO NOT EDIT (digest: 82230d61386befb40bc7377608e1f16e)
 set -e
 
 FST=true
@@ -23,5 +23,5 @@ for i in "$@"; do
   esac
 done
 
-make configure CONFIGUREFLAGS="$*"
+make configure CONFIGUREFLAGS="$@"
 # OASIS_STOP

+ 52 - 66
myocamlbuild.ml

@@ -1,7 +1,7 @@
 (* OASIS_START *)
-(* DO NOT EDIT (digest: 2b686a81cec9fb16d1640bda36a68fbd) *)
+(* DO NOT EDIT (digest: 4f240f06ff7a70bb4e3be1240a180aab) *)
 module OASISGettext = struct
-(* # 22 "src/oasis/OASISGettext.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISGettext.ml" *)
 
 
   let ns_ str =
@@ -30,7 +30,7 @@ module OASISGettext = struct
 end
 
 module OASISExpr = struct
-(* # 22 "src/oasis/OASISExpr.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/oasis/OASISExpr.ml" *)
 
 
 
@@ -39,10 +39,10 @@ module OASISExpr = struct
   open OASISGettext
 
 
-  type test = string
+  type test = string 
 
 
-  type flag = string
+  type flag = string 
 
 
   type t =
@@ -52,10 +52,10 @@ module OASISExpr = struct
     | EOr of t * t
     | EFlag of flag
     | ETest of test * string
+    
 
 
-
-  type 'a choices = (t * 'a) list
+  type 'a choices = (t * 'a) list 
 
 
   let eval var_get t =
@@ -131,7 +131,7 @@ end
 
 # 132 "myocamlbuild.ml"
 module BaseEnvLight = struct
-(* # 22 "src/base/BaseEnvLight.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/base/BaseEnvLight.ml" *)
 
 
   module MapString = Map.Make(String)
@@ -236,7 +236,7 @@ end
 
 # 237 "myocamlbuild.ml"
 module MyOCamlbuildFindlib = struct
-(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/MyOCamlbuildFindlib.ml" *)
 
 
   (** OCamlbuild extension, copied from
@@ -249,9 +249,6 @@ module MyOCamlbuildFindlib = struct
     *)
   open Ocamlbuild_plugin
 
-  type conf =
-    { no_automatic_syntax: bool;
-    }
 
   (* these functions are not really officially exported *)
   let run_and_read =
@@ -318,7 +315,7 @@ module MyOCamlbuildFindlib = struct
 
   (* This lists all supported packages. *)
   let find_packages () =
-    List.map before_space (split_nl & run_and_read (exec_from_conf "ocamlfind" ^ " list"))
+    List.map before_space (split_nl & run_and_read "ocamlfind list")
 
 
   (* Mock to list available syntaxes. *)
@@ -341,7 +338,7 @@ module MyOCamlbuildFindlib = struct
   ]
 
 
-  let dispatch conf =
+  let dispatch =
     function
       | After_options ->
           (* By using Before_options one let command line options have an higher
@@ -360,39 +357,31 @@ module MyOCamlbuildFindlib = struct
            * -linkpkg *)
           flag ["ocaml"; "link"; "program"] & A"-linkpkg";
 
-          if not (conf.no_automatic_syntax) then begin
-            (* For each ocamlfind package one inject the -package option when
-             * compiling, computing dependencies, generating documentation and
-             * linking. *)
-            List.iter
-              begin fun pkg ->
-                let base_args = [A"-package"; A pkg] in
-                (* TODO: consider how to really choose camlp4o or camlp4r. *)
-                let syn_args = [A"-syntax"; A "camlp4o"] in
-                let (args, pargs) =
-                  (* Heuristic to identify syntax extensions: whether they end in
-                     ".syntax"; some might not.
-                  *)
-                  if Filename.check_suffix pkg "syntax" ||
-                     List.mem pkg well_known_syntax then
-                    (syn_args @ base_args, syn_args)
-                  else
-                    (base_args, [])
-                in
-                flag ["ocaml"; "compile";  "pkg_"^pkg] & S args;
-                flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args;
-                flag ["ocaml"; "doc";      "pkg_"^pkg] & S args;
-                flag ["ocaml"; "link";     "pkg_"^pkg] & S base_args;
-                flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args;
-
-                (* TODO: Check if this is allowed for OCaml < 3.12.1 *)
-                flag ["ocaml"; "compile";  "package("^pkg^")"] & S pargs;
-                flag ["ocaml"; "ocamldep"; "package("^pkg^")"] & S pargs;
-                flag ["ocaml"; "doc";      "package("^pkg^")"] & S pargs;
-                flag ["ocaml"; "infer_interface"; "package("^pkg^")"] & S pargs;
-              end
-              (find_packages ());
-          end;
+          (* For each ocamlfind package one inject the -package option when
+           * compiling, computing dependencies, generating documentation and
+           * linking. *)
+          List.iter
+            begin fun pkg ->
+              let base_args = [A"-package"; A pkg] in
+              (* TODO: consider how to really choose camlp4o or camlp4r. *)
+              let syn_args = [A"-syntax"; A "camlp4o"] in
+              let args =
+              (* Heuristic to identify syntax extensions: whether they end in
+                 ".syntax"; some might not.
+               *)
+                if Filename.check_suffix pkg "syntax" ||
+                   List.mem pkg well_known_syntax then
+                  syn_args @ base_args
+                else
+                  base_args
+              in
+              flag ["ocaml"; "compile";  "pkg_"^pkg] & S args;
+              flag ["ocaml"; "ocamldep"; "pkg_"^pkg] & S args;
+              flag ["ocaml"; "doc";      "pkg_"^pkg] & S args;
+              flag ["ocaml"; "link";     "pkg_"^pkg] & S base_args;
+              flag ["ocaml"; "infer_interface"; "pkg_"^pkg] & S args;
+            end
+            (find_packages ());
 
           (* Like -package but for extensions syntax. Morover -syntax is useless
            * when linking. *)
@@ -426,7 +415,7 @@ module MyOCamlbuildFindlib = struct
 end
 
 module MyOCamlbuildBase = struct
-(* # 22 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
+(* # 22 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
 
 
   (** Base functions for writing myocamlbuild.ml
@@ -441,13 +430,13 @@ module MyOCamlbuildBase = struct
   module OC = Ocamlbuild_pack.Ocaml_compiler
 
 
-  type dir = string
-  type file = string
-  type name = string
-  type tag = string
+  type dir = string 
+  type file = string 
+  type name = string 
+  type tag = string 
 
 
-(* # 62 "src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
+(* # 62 "/home/lwzukw/.opam/4.01.0/build/oasis.0.4.4/src/plugins/ocamlbuild/MyOCamlbuildBase.ml" *)
 
 
   type t =
@@ -459,7 +448,7 @@ module MyOCamlbuildBase = struct
          * directory.
          *)
         includes:  (dir * dir list) list;
-      }
+      } 
 
 
   let env_filename =
@@ -557,13 +546,12 @@ module MyOCamlbuildBase = struct
 
                    (* When ocaml link something that use the C library, then one
                       need that file to be up to date.
-                      This holds both for programs and for libraries.
                     *)
-  		 dep ["link"; "ocaml"; tag_libstubs lib]
-  		     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
+                   dep ["link"; "ocaml"; "program"; tag_libstubs lib]
+                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
 
-  		 dep  ["compile"; "ocaml"; tag_libstubs lib]
-  		      [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
+                   dep  ["compile"; "ocaml"; "program"; tag_libstubs lib]
+                     [dir/"lib"^(nm_libstubs lib)^"."^(!Options.ext_lib)];
 
                    (* TODO: be more specific about what depends on headers *)
                    (* Depends on .h files *)
@@ -592,27 +580,25 @@ module MyOCamlbuildBase = struct
             ()
 
 
-  let dispatch_default conf t =
+  let dispatch_default t =
     dispatch_combine
       [
         dispatch t;
-        MyOCamlbuildFindlib.dispatch conf;
+        MyOCamlbuildFindlib.dispatch;
       ]
 
 
 end
 
 
-# 606 "myocamlbuild.ml"
+# 594 "myocamlbuild.ml"
 open Ocamlbuild_plugin;;
 let package_default =
   {MyOCamlbuildBase.lib_ocaml = []; lib_c = []; flags = []; includes = []}
   ;;
 
-let conf = {MyOCamlbuildFindlib.no_automatic_syntax = false}
-
-let dispatch_default = MyOCamlbuildBase.dispatch_default conf package_default;;
+let dispatch_default = MyOCamlbuildBase.dispatch_default package_default;;
 
-# 617 "myocamlbuild.ml"
+# 603 "myocamlbuild.ml"
 (* OASIS_STOP *)
 Ocamlbuild_plugin.dispatch dispatch_default;;

Fichier diff supprimé car celui-ci est trop grand
+ 174 - 210
setup.ml


+ 2 - 2
src/command_def.ml

@@ -54,7 +54,7 @@ let args =
     (* Flag to list each commands with its number *)
     +> flag "-l" no_arg
     ~aliases:["-list" ; "--list"]
-    ~doc:" Print a list of all command with its number. Useful to launch with number"
+    ~doc:" Print a list of all command with its number. Useful to launch with number. Displays a star next to next command to launch."
     (* Flag to add a command to rc file, from stdin or directly *)
     +> flag "-a" no_arg
     ~aliases:["-add" ; "--add"]
@@ -91,7 +91,7 @@ let commands =
        (* To delete command from rc file *)
        else if delete then Remove_command.run ~rc:rc_content num_cmd
        (* To print current state *)
-       else if number then State.current ()
+       else if number then State.print_current ()
        (* Reset to a value *)
        else if reset_tmp then Tmp_file.reset (Option.value ~default:0 num_cmd)
        (* Else: Run the nth command *)

+ 7 - 4
src/list_rc.ml

@@ -38,14 +38,17 @@ open Core.Std;;
 
 (* This modules contains function to list the content of the rc file *)
 
-(* Display the command with its number *)
-let disp_cmd_num number command =
-    printf "%i: %s\n" number command
+(* Display the command with its number, with a '*' if it is the current one *)
+let disp_cmd_num current_number number command =
+    (* If number is the global current one print a '*' *)
+    let prepend = (if current_number = number then "* " else "  ") in
+    printf "%s%i: %s\n" prepend number command
 ;;
 
 (* Function which list *)
 let run ~(rc:File_com.t) =
     (* We will use type rc_file *)
     let open Settings_t in
-    List.iteri rc.progs ~f:disp_cmd_num
+    List.iteri rc.progs ~f:(fun i item ->
+        disp_cmd_num (State.get_current ()) i item)
 ;;

+ 9 - 3
src/state.ml

@@ -38,12 +38,18 @@ open Core.Std;;
 
 (* Module to display the current state of the program *)
 
-(* Display current number *)
-let current () =
+(* Return current number *)
+let get_current () =
     (* We will use type tmp_file *)
     let open Tmp_biniou_t in
     (* Read tmp file *)
     let tmp_file = Tmp_file.init () in
+    (* Return the number *)
+    tmp_file.number;
+;;
+
+(* Display current number *)
+let print_current () =
     (* Display the number *)
-    printf "Current state: %i\n" tmp_file.number;
+    printf "Current state: %i\n" (get_current ())
 ;;