Use txt.conf:Authors for txt-new. Don't use Draft in filename

This commit is contained in:
orbifx 2022-11-19 11:37:52 +00:00
parent e1558b349a
commit ae2a76a6b3
2 changed files with 9 additions and 11 deletions

View File

@ -2,18 +2,16 @@ open Logarion
open Cmdliner open Cmdliner
let new_txt title topics_opt interactive = let new_txt title topics_opt interactive =
let t = match title with "" -> "Draft" | _ -> title in let kv = Logarion.File_store.of_kv_file () in
let authors = Person.Set.of_string (Sys.getenv "USER") in let authors = Person.Set.of_string (try Logarion.Store.KV.find "Authors" kv
let text = { (Text.blank ()) with title = t; authors } in with Not_found -> Sys.getenv "USER") in
let text = try Text.with_str_set text "Topics" (Option.get topics_opt) let text = { (Text.blank ()) with title; authors } in
with _ -> text in let text = try Text.with_str_set text "Topics" (Option.get topics_opt) with _->text in
match File_store.with_text text with match File_store.with_text text with
| Error s -> prerr_endline s | Error s -> prerr_endline s
| Ok (filepath, _note) -> | Ok (filepath, _note) ->
if not interactive then print_endline filepath if interactive then (Sys.command ("$EDITOR " ^ filepath) |> ignore);
else print_endline filepath
(print_endline @@ "Created: " ^ filepath;
Sys.command ("$EDITOR " ^ filepath) |> ignore)
let term = let term =
let title = Arg.(value & pos 0 string "" & info [] let title = Arg.(value & pos 0 string "" & info []

View File

@ -124,8 +124,8 @@ let versioned_basename_of_title ?(version=0) repo extension (title : string) =
next version next version
let id_filename repo extension text = let id_filename repo extension text =
let basename = Text.alias text in let description = match Text.alias text with "" -> "" | x -> "." ^ x in
let candidate = Filename.concat repo (text.id ^ "." ^ basename ^ extension) 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 if Sys.file_exists candidate then Error "Name clash, try again" else Ok candidate
let with_text ?(dir=txtdir ()) new_text = let with_text ?(dir=txtdir ()) new_text =