open Cmdliner let write_entry t (k, v) = Common.Log.info (fun m -> m "put %s=%s" k v); Sqlite.Kv.put t k v let write () db journal_mode pairs = Common.user_error ~db @@ fun () -> Eio_main.run @@ fun env -> Eio.Switch.run @@ fun sw -> Common.with_db env ~sw ~create:true ?journal_mode db (fun t -> List.iter (write_entry t) pairs); Common.Log.info (fun m -> m "wrote %d entries to %s" (List.length pairs) db) let cmd = let pairs = Arg.( value & pos_right 0 Common.kv_pair [] & info [] ~docv:"KEY=VALUE" ~doc:"Key-value pairs to write.") in let info = Cmd.info "write" ~doc:"Write key-value pairs to a database." ~man: [ `S Manpage.s_description; `P "Write key-value pairs to a database, creating it if needed."; `P "Use $(b,--journal-mode) to say how the commit reaches the file. \ It decides the mode a database being created is created in, and \ moves one that is already there."; `S Manpage.s_examples; `P "$(iname) mydb.db hello=world foo=bar"; `P "$(iname) --journal-mode=delete mydb.db hello=world"; ] in Cmd.v info Term.( const write $ Common.logging $ Common.db_arg $ Common.journal_mode $ pairs)