mirror of
https://github.com/chshersh/github-tui.git
synced 2024-08-17 22:40:41 +03:00
Refactor initial_data into a separate type
This commit is contained in:
parent
d0647d54ef
commit
d8a889e117
@ -11,7 +11,7 @@ let path_arg =
|
||||
& opt string "."
|
||||
& info [ "d"; "directory" ] ~docv:"DIRECTORY_PATH" ~doc)
|
||||
|
||||
let gh_tui_t = Term.(const Tui.App.start $ repo_arg $ path_arg)
|
||||
let gh_tui_term = Term.(const Tui.App.start $ repo_arg $ path_arg)
|
||||
|
||||
let cmd =
|
||||
let doc = "TUI of a GitHub repository" in
|
||||
@ -22,4 +22,4 @@ let cmd =
|
||||
]
|
||||
in
|
||||
let info = Cmd.info "gh-tui" ~version:"0.1.0" ~doc ~man in
|
||||
Cmd.v info gh_tui_t
|
||||
Cmd.v info gh_tui_term
|
||||
|
@ -1,11 +1,14 @@
|
||||
let app = Minttea.app ~init:Init.init ~update:Update.update ~view:View.view ()
|
||||
|
||||
let start repo path =
|
||||
let init ~repo ~path : Model.initial_data =
|
||||
let tree = Fs.read_tree path in
|
||||
match tree with
|
||||
| Fs.File path ->
|
||||
Printf.printf "Given path '%s' is not a directory!" path;
|
||||
exit 1
|
||||
| Fs.Dir (dirname, files) ->
|
||||
let initial_model = Model.initial_model ~repo ~dirname ~files in
|
||||
| Fs.Dir (dirname, files) -> { repo; dirname; files }
|
||||
|
||||
let app = Minttea.app ~init:Init.init ~update:Update.update ~view:View.view ()
|
||||
|
||||
let start repo path =
|
||||
let initial_data = init ~repo ~path in
|
||||
let initial_model = Model.initial_model initial_data in
|
||||
Minttea.start app ~initial_model
|
||||
|
@ -16,5 +16,11 @@ type t = {
|
||||
code_tab : code_tab;
|
||||
}
|
||||
|
||||
let initial_model ~repo ~dirname ~files =
|
||||
type initial_data = {
|
||||
repo : string;
|
||||
dirname : string;
|
||||
files : Fs.tree array;
|
||||
}
|
||||
|
||||
let initial_model { repo; dirname; files } =
|
||||
{ repo; current_tab = Code; code_tab = { dirname; fs = Fs.zip_it files } }
|
||||
|
Loading…
Reference in New Issue
Block a user