From ae2a76a6b3924af9fad575c8686e7078d1147456 Mon Sep 17 00:00:00 2001 From: orbifx Date: Sat, 19 Nov 2022 11:37:52 +0000 Subject: [PATCH] Use txt.conf:Authors for txt-new. Don't use Draft in filename --- cli/new.ml | 16 +++++++--------- lib/file_store.ml | 4 ++-- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/cli/new.ml b/cli/new.ml index 0b429e3..aeccba6 100644 --- a/cli/new.ml +++ b/cli/new.ml @@ -2,18 +2,16 @@ open Logarion open Cmdliner let new_txt title topics_opt interactive = - let t = match title with "" -> "Draft" | _ -> title in - let authors = Person.Set.of_string (Sys.getenv "USER") in - let text = { (Text.blank ()) with title = t; authors } in - let text = try Text.with_str_set text "Topics" (Option.get topics_opt) - with _ -> text in + let kv = Logarion.File_store.of_kv_file () in + let authors = Person.Set.of_string (try Logarion.Store.KV.find "Authors" kv + with Not_found -> Sys.getenv "USER") in + let text = { (Text.blank ()) with title; authors } in + let text = try Text.with_str_set text "Topics" (Option.get topics_opt) with _->text in match File_store.with_text text with | Error s -> prerr_endline s | Ok (filepath, _note) -> - if not interactive then print_endline filepath - else - (print_endline @@ "Created: " ^ filepath; - Sys.command ("$EDITOR " ^ filepath) |> ignore) + if interactive then (Sys.command ("$EDITOR " ^ filepath) |> ignore); + print_endline filepath let term = let title = Arg.(value & pos 0 string "" & info [] diff --git a/lib/file_store.ml b/lib/file_store.ml index e8a5616..d2d633c 100644 --- a/lib/file_store.ml +++ b/lib/file_store.ml @@ -124,8 +124,8 @@ let versioned_basename_of_title ?(version=0) repo extension (title : string) = next version let id_filename repo extension text = - let basename = Text.alias text in - let candidate = Filename.concat repo (text.id ^ "." ^ basename ^ extension) in + let description = match Text.alias text with "" -> "" | x -> "." ^ x in + let candidate = Filename.concat repo (text.id ^ description ^ extension) in if Sys.file_exists candidate then Error "Name clash, try again" else Ok candidate let with_text ?(dir=txtdir ()) new_text =