|
1 | | -type owner_repo = { |
2 | | - owner : string; |
3 | | - repo : string; |
4 | | -} |
5 | | - |
6 | | -let parse_owner_repo owner_repo = |
7 | | - match String.split_on_char '/' owner_repo with |
8 | | - | [ owner; repo ] -> { owner; repo } |
9 | | - | _ -> |
10 | | - Printf.eprintf "❌ Expected <owner>/<repo> but got: '%s'\n" owner_repo; |
11 | | - exit 1 |
12 | | - |
13 | | -let clone_repo ~owner_repo ~local_path = |
14 | | - match local_path with |
15 | | - | Some path -> path |
16 | | - | None -> |
17 | | - let { owner; repo } = owner_repo in |
18 | | - let temp_dir = |
19 | | - Filename.temp_dir "github-tui-" (Printf.sprintf "%s-%s" owner repo) |
20 | | - in |
21 | | - let cmd = |
22 | | - Printf.sprintf "git clone [email protected]:%s/%s.git %s" owner repo |
23 | | - temp_dir |
24 | | - in |
25 | | - Shell.proc cmd; |
26 | | - temp_dir |
27 | | - |
28 | | -let read_root_tree ~root_dir_path = |
29 | | - let tree = Fs.read_tree root_dir_path in |
30 | | - let files = |
31 | | - match tree with |
32 | | - | Fs.File { name; _ } -> |
33 | | - Printf.eprintf "Given path '%s' is not a directory!" name; |
34 | | - exit 1 |
35 | | - | Fs.Dir { children = files; _ } -> files |
36 | | - in |
37 | | - files |
38 | | - |
39 | | -type terminal = { |
40 | | - height : int; |
41 | | - width : int; |
42 | | -} |
43 | | - |
44 | | -let min_height, min_width = (40, 140) |
45 | | - |
46 | | -let get_terminal_dimensions ignore_size_warning = |
47 | | - match (Terminal_size.get_rows (), Terminal_size.get_columns ()) with |
48 | | - | Some height, Some width -> |
49 | | - if (not ignore_size_warning) && (height < min_height || width < min_width) |
50 | | - then ( |
51 | | - Printf.eprintf |
52 | | - {|⚠️ Terminal size is too small! GitHub TUI works better on bigger terminals. |
53 | | - Expected size: %3d width x %3d height |
54 | | - But got: %3d width x %3d height |
55 | | - |
56 | | - Pass the --ignore-size-warning flag to run anyway. |
57 | | -|} |
58 | | - min_width min_height width height; |
59 | | - exit 1); |
60 | | - { height; width } |
61 | | - | _ -> |
62 | | - Printf.eprintf "⚠️ Not able to get the terminal size.\n"; |
63 | | - exit 1 |
64 | | - |
65 | | -let init ~owner_repo ~local_path ~ignore_size_warning : Model.initial_data = |
66 | | - let ({ owner; repo } as owner_repo) = parse_owner_repo owner_repo in |
67 | | - let root_dir_path = clone_repo ~owner_repo ~local_path in |
68 | | - let files = Lazy.force (read_root_tree ~root_dir_path) in |
69 | | - let { height; width } = get_terminal_dimensions ignore_size_warning in |
70 | | - { owner; repo; root_dir_path; files; width; height } |
71 | | - |
72 | | -let start ~owner_repo ~local_path ~log_file ~ignore_size_warning = |
73 | | - let initial_data = init ~owner_repo ~local_path ~ignore_size_warning in |
| 1 | +let start args = |
| 2 | + let initial_data = Init.init args in |
74 | 3 | let init = Model.initial_model initial_data in |
75 | 4 | let app = Tea.make ~init ~update:Update.update ~view:View.view in |
76 | | - Tea.run ?path:log_file app |
| 5 | + Tea.run ?path:args.log_file app |
0 commit comments