source: code/trunk/cli/new.ml@ 59

Last change on this file since 59 was 32, checked in by fox, 2 years ago

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

File size: 1.1 KB
Line 
1open Logarion
2open Cmdliner
3
4let new_txt title topics_opt interactive =
5 let kv = Logarion.File_store.of_kv_file () in
6 let authors = Person.Set.of_string (try Logarion.Store.KV.find "Authors" kv
7 with Not_found -> Sys.getenv "USER") in
8 let text = { (Text.blank ()) with title; authors } in
9 let text = try Text.with_str_set text "Topics" (Option.get topics_opt) with _->text in
10 match File_store.with_text text with
11 | Error s -> prerr_endline s
12 | Ok (filepath, _note) ->
13 if interactive then (Sys.command ("$EDITOR " ^ filepath) |> ignore);
14 print_endline filepath
15
16let term =
17 let title = Arg.(value & pos 0 string "" & info []
18 ~docv:"title" ~doc:"Title for new article") in
19 let topics= Arg.(value & opt (some string) None & info ["t"; "topics"]
20 ~docv:"comma-separated topics" ~doc:"Topics for new article") in
21 let inter = Arg.(value & flag & info ["i"; "interactive"]
22 ~doc:"Prompts through the steps of creation") in
23 Term.(const new_txt $ title $ topics $ inter), Term.info "new"
24 ~doc:"create a new article" ~man:[ `S "DESCRIPTION";
25 `P "Create a new article, with title 'Draft' when none provided"]
Note: See TracBrowser for help on using the repository browser.