|
1 | | -module StringSet = Set.Make (String) |
2 | | - |
3 | | -let parseArgs args = |
4 | | - match args with |
5 | | - | [] -> assert false |
6 | | - | _ :: args -> |
7 | | - let opts, pos = |
8 | | - args |> List.rev |
9 | | - |> List.fold_left |
10 | | - (fun (set, pos) arg -> |
11 | | - if arg <> "" && arg.[0] = '-' then (set |> StringSet.add arg, pos) |
12 | | - else (set, arg :: pos)) |
13 | | - (StringSet.empty, []) |
14 | | - in |
15 | | - (opts, pos) |
16 | | - |
17 | | -let hasOpt opts name = opts |> StringSet.mem name |
18 | | - |
19 | | -let hasOpts opts names = names |> List.exists (opts |> hasOpt) |
20 | | - |
21 | 1 | let help = |
22 | 2 | {| |
23 | 3 | **Private CLI For rescript-vscode usage only** |
@@ -50,19 +30,19 @@ Options: |
50 | 30 | let showHelp () = prerr_endline help |
51 | 31 |
|
52 | 32 | let main () = |
53 | | - match parseArgs (Sys.argv |> Array.to_list) with |
54 | | - | opts, _ when hasOpts opts ["-h"; "--help"] -> showHelp () |
55 | | - | _opts, "dump" :: files -> EditorSupportCommands.dump files |
56 | | - | _opts, ["complete"; path; line; col; currentFile] -> |
| 33 | + match Array.to_list Sys.argv with |
| 34 | + | [_; "complete"; path; line; col; currentFile] -> |
57 | 35 | EditorSupportCommands.complete ~path ~line:(int_of_string line) |
58 | 36 | ~col:(int_of_string col) ~currentFile |
59 | | - | _opts, ["hover"; path; line; col] -> |
| 37 | + | [_; "hover"; path; line; col] -> |
60 | 38 | EditorSupportCommands.hover ~path ~line:(int_of_string line) |
61 | 39 | ~col:(int_of_string col) |
62 | | - | _opts, ["definition"; path; line; col] -> |
| 40 | + | [_; "definition"; path; line; col] -> |
63 | 41 | EditorSupportCommands.definition ~path ~line:(int_of_string line) |
64 | 42 | ~col:(int_of_string col) |
65 | | - | _opts, ["test"; path] -> EditorSupportCommands.test ~path |
| 43 | + | _ :: "dump" :: files -> EditorSupportCommands.dump files |
| 44 | + | [_; "test"; path] -> EditorSupportCommands.test ~path |
| 45 | + | args when List.mem "-h" args || List.mem "--help" args -> showHelp () |
66 | 46 | | _ -> |
67 | 47 | showHelp (); |
68 | 48 | exit 1 |
|
0 commit comments