Commit
+31 -8 +/-3 browse
1 | diff --git a/lib/cmd.ml b/lib/cmd.ml |
2 | index 1d7df88..8d4c083 100644 |
3 | --- a/lib/cmd.ml |
4 | +++ b/lib/cmd.ml |
5 | @@ -75,7 +75,7 @@ note cat -encoding json |
6 | |
7 | let config_show = |
8 | Command.basic ~summary:"show the current configuration" |
9 | - (Command.Param.return (fun () -> print_string (to_string load))) |
10 | + (Command.Param.return (fun () -> print_string (to_string (populate load)))) |
11 | |
12 | let config_get = |
13 | let open Command.Let_syntax in |
14 | @@ -206,7 +206,7 @@ note edit fuubar |
15 | let list_notes = |
16 | let open Note.Display in |
17 | let open Command.Let_syntax in |
18 | - Command.basic ~summary:"list notes" |
19 | + Command.basic ~summary:"list existing notes" |
20 | ~readme:(fun () -> |
21 | {| |
22 | List notes that match the filter criteria, if no filter criteria is given all notes will be listed |
23 | @@ -242,7 +242,14 @@ note ls |
24 | Note.Filter.find_many ?strategy:filter_kind ~args:filter_args |
25 | get_notes |
26 | in |
27 | - to_stdout ~columns: columns ~style notes] |
28 | + to_stdout ~columns ~style notes] |
29 | + |
30 | + let sync = |
31 | + Command.basic ~summary:"sync notes to a remote server" |
32 | + (Command.Param.return (fun () -> |
33 | + let cfg = load in |
34 | + let on_sync = Config.get_string_opt cfg `OnSync in |
35 | + Sync.sync on_sync)) |
36 | |
37 | let run = |
38 | Command.run ~version:"%%VERSION%%" |
39 | @@ -257,4 +264,5 @@ let run = |
40 | ("delete", delete_note); |
41 | ("edit", edit_note); |
42 | ("ls", list_notes); |
43 | + ("sync", sync); |
44 | ]) |
45 | diff --git a/lib/config.ml b/lib/config.ml |
46 | index 2d24e5b..b2cb6c9 100644 |
47 | --- a/lib/config.ml |
48 | +++ b/lib/config.ml |
49 | @@ -67,6 +67,7 @@ module Key = struct |
50 | | `LockFile |
51 | | `Editor |
52 | | `OnModification |
53 | + | `OnSync |
54 | | `ListStyle |
55 | | `Encoding |
56 | | `ColumnList ] |
57 | @@ -77,6 +78,7 @@ module Key = struct |
58 | `LockFile; |
59 | `Editor; |
60 | `OnModification; |
61 | + `OnSync; |
62 | `ListStyle; |
63 | `Encoding; |
64 | `ColumnList; |
65 | @@ -87,6 +89,7 @@ module Key = struct |
66 | | "lock_file" -> `LockFile |
67 | | "editor" -> `Editor |
68 | | "on_modification" -> `OnModification |
69 | + | "on_sync" -> `OnSync |
70 | | "list_style" -> `ListStyle |
71 | | "encoding" -> `Encoding |
72 | | "column_list" -> `ColumnList |
73 | @@ -97,6 +100,7 @@ module Key = struct |
74 | | `LockFile -> "lock_file" |
75 | | `Editor -> "editor" |
76 | | `OnModification -> "on_modification" |
77 | + | `OnSync -> "on_sync" |
78 | | `ListStyle -> "list_style" |
79 | | `Encoding -> "encoding" |
80 | | `ColumnList -> "column_list" |
81 | @@ -117,6 +121,7 @@ let get_default = function |
82 | | `LockFile -> String (Some (Filename.concat base_xdg_share_path "/note")) |
83 | | `Editor -> String (Sys.getenv "EDITOR") |
84 | | `OnModification -> String None |
85 | + | `OnSync -> String None |
86 | | `ListStyle -> ListStyle (Some `Fixed) |
87 | | `Encoding -> Encoding (Some `Raw) |
88 | | `ColumnList -> ColumnList (Some [ `Title; `Tags; `WordCount; `Slug ]) |
89 | @@ -127,6 +132,7 @@ let value_of_string key s = |
90 | | `LockFile -> String (Some s) |
91 | | `Editor -> String (Some s) |
92 | | `OnModification -> String (Some s) |
93 | + | `OnSync -> String (Some s) |
94 | | `ListStyle -> ListStyle (Some (ListStyle.of_string s)) |
95 | | `Encoding -> Encoding (Some (Encoding.of_string s)) |
96 | | `ColumnList -> ColumnList (Some (Column.of_string_list s)) |
97 | @@ -143,9 +149,7 @@ let value_to_string value = |
98 | |
99 | let get t key = |
100 | match Ezjsonm.find_opt t [ Key.to_string key ] with |
101 | - | Some json -> |
102 | - value_of_string key (Ezjsonm.get_string json) |
103 | - |
104 | + | Some json -> value_of_string key (Ezjsonm.get_string json) |
105 | | None -> get_default key |
106 | |
107 | let set t key value = |
108 | @@ -168,8 +172,7 @@ let get_string t key = |
109 | let load = |
110 | let cfg = |
111 | match Sys.file_exists config_path with |
112 | - | `Yes -> |
113 | - Yaml.of_string_exn (In_channel.read_all config_path) |
114 | + | `Yes -> Yaml.of_string_exn (In_channel.read_all config_path) |
115 | | `No | `Unknown -> |
116 | Unix.mkdir_p (Filename.dirname config_path); |
117 | Out_channel.write_all config_path |
118 | @@ -185,4 +188,10 @@ let load = |
119 | Unix.mkdir_p state_dir; |
120 | cfg |
121 | |
122 | + let populate t = |
123 | + List.fold ~init:t ~f: (fun accm key -> |
124 | + let value = get accm key in |
125 | + set accm key value |
126 | + ) Key.all |
127 | + |
128 | let save t = Out_channel.write_all ~data:(to_string t) config_path |
129 | diff --git a/lib/sync.ml b/lib/sync.ml |
130 | new file mode 100644 |
131 | index 0000000..70f6507 |
132 | --- /dev/null |
133 | +++ b/lib/sync.ml |
134 | @@ -0,0 +1,6 @@ |
135 | + open Core |
136 | + |
137 | + let sync on_sync = |
138 | + match on_sync with |
139 | + | Some cmd -> Sys.command_exn cmd |
140 | + | None -> () |