Commits

Paweł Wieczorek committed d9d1b2e Draft

Some cleaning

  • Participants
  • Parent commits 0531471

Comments (0)

Files changed (2)

File src/Executor.ml

 let usage_of_node path hash_table = String.concat "\n"
     [ "usage: " ^ print_path path
     ; ""
-    ; "available commands:"
+    ; "List of available commands:"
     ; list_of_available_commands hash_table
     ]
 

File src/GetOpt.ml

 open Type
 
 (*********************************************************************************************************************
- * Private
+ * Helpers
+ ********************************************************************************************************************)
+
+let get_short_name = function
+    | WithArgument (_, _, Some short, _, _) -> Some ("-" ^ String.make 1 short)
+    | WithoutArgument (_, Some short, _, _) -> Some ("-" ^ String.make 1 short)
+    | _ -> None
+
+
+let get_long_name = function
+    | WithArgument (_, _, _, Some long, _) -> Some ("--" ^ long)
+    | WithoutArgument (_, _, Some long, _) -> Some ("--" ^ long)
+    | _ -> None
+
+let is_looking_like_option argument =
+       (String.length argument == 2 && argument.[0] = '-')
+    || (String.length argument > 2  && argument.[0] = '-' && argument.[1] = '-')
+
+(*********************************************************************************************************************
+ * Mapping
  ********************************************************************************************************************)
 
 let create_mapping get_key options =
     List.iter update_mapping options;
     mapping
 
-let get_short_name = function
-    | WithArgument (_, _, Some short, _, _) -> Some ("-" ^ String.make 1 short)
-    | WithoutArgument (_, Some short, _, _) -> Some ("-" ^ String.make 1 short)
-    | _ -> None
-
-
-let get_long_name = function
-    | WithArgument (_, _, _, Some long, _) -> Some ("--" ^ long)
-    | WithoutArgument (_, _, Some long, _) -> Some ("--" ^ long)
-    | _ -> None
-
-
 let create_mappings options =
     ( create_mapping get_short_name options
     , create_mapping get_long_name options
         | found ->
             found
 
+(*********************************************************************************************************************
+ * Helpers
+ ********************************************************************************************************************)
+
 let rec compute_flags mappings result = function
     | "--"::xs ->
         (List.rev result, xs)
 
-    | x::xs when is_option x ->
+    | x::xs when is_looking_like_option x ->
         begin match check_argument_in_mappings mappings x with
             | None ->
                 raise (Invalid_usage ("unknown option: " ^ x))
         (List.rev result, xs)
 
 and obtain_argument_for_option mappings result flag_func name passed_argument = function
-    | [] ->
-        raise (Invalid_usage ("argument required for: " ^ passed_argument))
-
     | x::xs ->
         compute_flags mappings (flag_func x :: result) xs
 
-and is_option argument =
-       (String.length argument == 2 && argument.[0] = '-')
-    || (String.length argument > 2  && argument.[0] = '-' && argument.[1] = '-')
+    | _ ->
+        raise (Invalid_usage ("argument required for: " ^ passed_argument))
+
+
+(*********************************************************************************************************************
+ * Helper printer
+ ********************************************************************************************************************)
 
 
 let print_option_flag short long argname =
     ; output
     ]
 
+(*********************************************************************************************************************
+ * Entry
+ ********************************************************************************************************************)
 
 let getopt options arguments = 
     let mappings = create_mappings options in