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
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 []

View File

@ -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 =