aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMarc Coquand <marc@mccd.space>2024-05-19 08:50:43 -0500
committerMarc Coquand <marc@mccd.space>2024-05-19 08:50:43 -0500
commitb9728e919b074b2bf9690eca04d8d96e64b3207a (patch)
treee27415e932c4f19f78ac5bcd50e2c06543af8c91 /lib
parentc3a52f259f3a3b70ab25fba98ab7450e0fa69e67 (diff)
downloadstitch-b9728e919b074b2bf9690eca04d8d96e64b3207a.tar.gz
stitch-b9728e919b074b2bf9690eca04d8d96e64b3207a.tar.bz2
stitch-b9728e919b074b2bf9690eca04d8d96e64b3207a.zip
Set Stitch to fail if STITCH_DIRECTORY is not set
Diffstat (limited to 'lib')
-rw-r--r--lib/stitch.ml105
1 files changed, 56 insertions, 49 deletions
diff --git a/lib/stitch.ml b/lib/stitch.ml
index 2fc0a9c..31c247d 100644
--- a/lib/stitch.ml
+++ b/lib/stitch.ml
@@ -12,52 +12,59 @@ let start (tag : string) () =
It does create a rather funky, cyclical state though.
*)
- let term = Common.Term.create () in
- let restore_headline_state = ref (fun () -> ()) in
- let restore_done_state = ref (fun () -> ()) in
- let restore_todo_state = ref (fun () -> ()) in
- (* DONE *)
- let goto_todo_from_done new_done_state =
- restore_done_state := new_done_state;
- !restore_todo_state ()
- in
- let goto_headlines_from_done new_done_state =
- restore_done_state := new_done_state;
- !restore_headline_state ()
- in
- (restore_done_state
- := fun () ->
- let done_state =
- Done.init
- ~goto_headlines:goto_headlines_from_done
- ~goto_todo:goto_todo_from_done
- in
- Done.render term done_state);
- (* TODO *)
- let goto_done_from_todo new_todo_state =
- restore_todo_state := new_todo_state;
- !restore_done_state ()
- in
- let goto_headline_from_todo new_todo_state =
- restore_todo_state := new_todo_state;
- !restore_headline_state ()
- in
- (restore_todo_state
- := fun () ->
- let todo =
- Todos.init
- ~goto_headlines:goto_headline_from_todo
- ~goto_done:goto_done_from_todo
- in
- Todos.render term todo);
- let headline =
- Headlines.init
- ~goto_done_view:(fun new_state ->
- restore_headline_state := new_state;
- !restore_done_state ())
- ~goto_todos_view:(fun new_state ->
- restore_headline_state := new_state;
- !restore_todo_state ())
- ~regexp:tag
- in
- Headlines.render term headline
+ if String.equal String.empty (String.trim Grep.execution_directory)
+ then
+ print_endline
+ "Execution directory is not set. You will need to set environment variable \
+ STITCH_DIRECTORY to the absolute path of your notes. For example: \
+ STITCH_DIRECTORY='/home/you/notes'."
+ else (
+ let term = Common.Term.create () in
+ let restore_headline_state = ref (fun () -> ()) in
+ let restore_done_state = ref (fun () -> ()) in
+ let restore_todo_state = ref (fun () -> ()) in
+ (* DONE *)
+ let goto_todo_from_done new_done_state =
+ restore_done_state := new_done_state;
+ !restore_todo_state ()
+ in
+ let goto_headlines_from_done new_done_state =
+ restore_done_state := new_done_state;
+ !restore_headline_state ()
+ in
+ (restore_done_state
+ := fun () ->
+ let done_state =
+ Done.init
+ ~goto_headlines:goto_headlines_from_done
+ ~goto_todo:goto_todo_from_done
+ in
+ Done.render term done_state);
+ (* TODO *)
+ let goto_done_from_todo new_todo_state =
+ restore_todo_state := new_todo_state;
+ !restore_done_state ()
+ in
+ let goto_headline_from_todo new_todo_state =
+ restore_todo_state := new_todo_state;
+ !restore_headline_state ()
+ in
+ (restore_todo_state
+ := fun () ->
+ let todo =
+ Todos.init
+ ~goto_headlines:goto_headline_from_todo
+ ~goto_done:goto_done_from_todo
+ in
+ Todos.render term todo);
+ let headline =
+ Headlines.init
+ ~goto_done_view:(fun new_state ->
+ restore_headline_state := new_state;
+ !restore_done_state ())
+ ~goto_todos_view:(fun new_state ->
+ restore_headline_state := new_state;
+ !restore_todo_state ())
+ ~regexp:tag
+ in
+ Headlines.render term headline)