Commit
+66 -73 +/-3 browse
1 | diff --git a/lib/cmd.ml b/lib/cmd.ml |
2 | index 4666797..1e9b74d 100644 |
3 | --- a/lib/cmd.ml |
4 | +++ b/lib/cmd.ml |
5 | @@ -6,7 +6,7 @@ let get_notes = |
6 | ~f:(fun slug -> |
7 | let data = In_channel.read_all (Slug.get_path slug) in |
8 | Note.of_string ~data slug) |
9 | - (Slug.load (get_string load StateDir)) |
10 | + (Slug.load (get_string load `StateDir)) |
11 | |
12 | let filter_arg = |
13 | Command.Arg_type.create |
14 | @@ -58,7 +58,7 @@ note cat -encoding json |
15 | and encoding = |
16 | flag "encoding" |
17 | (optional_with_default |
18 | - (Encoding.of_string (value_to_string (get load Key.Encoding))) |
19 | + (Encoding.of_string (value_to_string (get load `Encoding))) |
20 | (Command.Arg_type.create Encoding.of_string)) |
21 | ~doc:"format [json | yaml | raw] (default: raw)" |
22 | in |
23 | @@ -70,11 +70,7 @@ note cat -encoding json |
24 | in |
25 | List.iter |
26 | ~f:(fun note -> |
27 | - print_endline |
28 | - ( match encoding with |
29 | - | Json -> Note.Encoding.to_string ~style:`Json note |
30 | - | Yaml -> Note.Encoding.to_string ~style:`Yaml note |
31 | - | Raw -> Note.Encoding.to_string ~style:`Raw note )) |
32 | + print_endline (Note.Encoding.to_string ~style:encoding note)) |
33 | notes] |
34 | |
35 | let config_show = |
36 | @@ -127,21 +123,21 @@ note ls "My Important Note" |
37 | and tags = anon (sequence ("tag" %: string)) in |
38 | fun () -> |
39 | let cfg = load in |
40 | - let slug = Slug.next (get_string cfg Key.StateDir) in |
41 | + let slug = Slug.next (get_string cfg `StateDir) in |
42 | match open_stdin with |
43 | | Some _ -> |
44 | (* reading from stdin so write directly to note *) |
45 | let content = In_channel.input_all In_channel.stdin in |
46 | let note = Note.build ~tags ~content ~title slug in |
47 | Io.create |
48 | - ~callback:(get_string_opt cfg Key.OnModification) |
49 | + ~callback:(get_string_opt cfg `OnModification) |
50 | ~content:(Note.to_string note) (Slug.get_path slug) |
51 | | None -> |
52 | let note = Note.build ~tags ~content:"" ~title slug in |
53 | let init_content = Note.to_string note in |
54 | Io.create_on_change |
55 | - ~callback:(get_string_opt cfg Key.OnModification) |
56 | - ~editor:(get_string cfg Key.Editor) |
57 | + ~callback:(get_string_opt cfg `OnModification) |
58 | + ~editor:(get_string cfg `Editor) |
59 | init_content (Slug.get_path slug)] |
60 | |
61 | let delete_note = |
62 | @@ -172,7 +168,7 @@ note delete fuubar |
63 | match note with |
64 | | Some note -> |
65 | Io.delete |
66 | - ~callback:(get_string_opt load Key.OnModification) |
67 | + ~callback:(get_string_opt load `OnModification) |
68 | ~title:(Note.get_title note) (Note.get_path note) |
69 | | None -> failwith "not found"] |
70 | |
71 | @@ -202,8 +198,8 @@ note edit fuubar |
72 | match note with |
73 | | Some note -> |
74 | Io.edit |
75 | - ~callback:(get_string_opt cfg Key.OnModification) |
76 | - ~editor:(get_string cfg Key.Editor) |
77 | + ~callback:(get_string_opt cfg `OnModification) |
78 | + ~editor:(get_string cfg `Editor) |
79 | (Note.get_path note) |
80 | | None -> failwith "not found"] |
81 | |
82 | @@ -229,7 +225,7 @@ note ls |
83 | and style = |
84 | flag "style" |
85 | (optional_with_default |
86 | - (ListStyle.of_string (value_to_string (get load Key.ListStyle))) |
87 | + (ListStyle.of_string (value_to_string (get load `ListStyle))) |
88 | (Arg_type.create ListStyle.of_string)) |
89 | ~doc:"list style [fixed | wide | simple]" |
90 | in |
91 | @@ -240,10 +236,7 @@ note ls |
92 | Note.Filter.find_many ?strategy:filter_kind ~args:filter_args |
93 | get_notes |
94 | in |
95 | - match style with |
96 | - | ListStyle.Fixed -> to_stdout ~style:`Fixed notes |
97 | - | ListStyle.Wide -> to_stdout ~style:`Wide notes |
98 | - | ListStyle.Simple -> to_stdout ~style:`Simple notes] |
99 | + to_stdout ~style notes] |
100 | |
101 | let run = |
102 | Command.run ~version:"%%VERSION%%" |
103 | diff --git a/lib/config.ml b/lib/config.ml |
104 | index ee2be07..a15d752 100644 |
105 | --- a/lib/config.ml |
106 | +++ b/lib/config.ml |
107 | @@ -12,60 +12,60 @@ let config_path = |
108 | | None -> Filename.concat base_xdg_config_path "/note/config.yaml" |
109 | |
110 | module ListStyle = struct |
111 | - type t = Fixed | Wide | Simple |
112 | + type t = [ `Fixed | `Wide | `Simple ] |
113 | |
114 | let to_string = function |
115 | - | Fixed -> "fixed" |
116 | - | Wide -> "wide" |
117 | - | Simple -> "simple" |
118 | + | `Fixed -> "fixed" |
119 | + | `Wide -> "wide" |
120 | + | `Simple -> "simple" |
121 | |
122 | let of_string = function |
123 | - | "fixed" -> Fixed |
124 | - | "wide" -> Wide |
125 | - | "simple" -> Simple |
126 | + | "fixed" -> `Fixed |
127 | + | "wide" -> `Wide |
128 | + | "simple" -> `Simple |
129 | | key -> failwith key |
130 | end |
131 | |
132 | module Encoding = struct |
133 | - type t = Json | Yaml | Raw |
134 | + type t = [ `Json | `Yaml | `Raw ] |
135 | |
136 | - let to_string = function Json -> "json" | Yaml -> "yaml" | Raw -> "raw" |
137 | + let to_string = function `Json -> "json" | `Yaml -> "yaml" | `Raw -> "raw" |
138 | |
139 | let of_string = function |
140 | - | "json" -> Json |
141 | - | "yaml" -> Yaml |
142 | - | "raw" -> Raw |
143 | + | "json" -> `Json |
144 | + | "yaml" -> `Yaml |
145 | + | "raw" -> `Raw |
146 | | key -> failwith (sprintf "unsupported encoding type: %s" key) |
147 | end |
148 | |
149 | module Key = struct |
150 | type t = |
151 | - | StateDir |
152 | - | LockFile |
153 | - | Editor |
154 | - | OnModification |
155 | - | ListStyle |
156 | - | Encoding |
157 | + [ `StateDir |
158 | + | `LockFile |
159 | + | `Editor |
160 | + | `OnModification |
161 | + | `ListStyle |
162 | + | `Encoding ] |
163 | |
164 | - let all = [ StateDir; LockFile; Editor; OnModification; ListStyle; Encoding ] |
165 | + let all = |
166 | + [ `StateDir; `LockFile; `Editor; `OnModification; `ListStyle; `Encoding ] |
167 | |
168 | let of_string = function |
169 | - | "state_dir" -> StateDir |
170 | - | "lock_file" -> LockFile |
171 | - | "editor" -> Editor |
172 | - | "on_modification" -> OnModification |
173 | - | "list_style" -> ListStyle |
174 | - | "encoding" -> Encoding |
175 | + | "state_dir" -> `StateDir |
176 | + | "lock_file" -> `LockFile |
177 | + | "editor" -> `Editor |
178 | + | "on_modification" -> `OnModification |
179 | + | "list_style" -> `ListStyle |
180 | + | "encoding" -> `Encoding |
181 | | key -> failwith (sprintf "bad configuration key %s" key) |
182 | |
183 | let to_string = function |
184 | - | StateDir -> "state_dir" |
185 | - | LockFile -> "lock_file" |
186 | - | Editor -> "editor" |
187 | - | OnModification -> "on_modification" |
188 | - | ListStyle -> "list_style" |
189 | - | Encoding -> "encoding" |
190 | - |
191 | + | `StateDir -> "state_dir" |
192 | + | `LockFile -> "lock_file" |
193 | + | `Editor -> "editor" |
194 | + | `OnModification -> "on_modification" |
195 | + | `ListStyle -> "list_style" |
196 | + | `Encoding -> "encoding" |
197 | end |
198 | |
199 | type t = Yaml.value |
200 | @@ -78,21 +78,21 @@ type value = |
201 | | Encoding of Encoding.t option |
202 | |
203 | let get_default = function |
204 | - | Key.StateDir -> String (Some (Filename.concat base_xdg_share_path "/note")) |
205 | - | Key.LockFile -> String (Some (Filename.concat base_xdg_share_path "/note")) |
206 | - | Key.Editor -> String (Sys.getenv "EDITOR") |
207 | - | Key.OnModification -> String None |
208 | - | Key.ListStyle -> ListStyle (Some ListStyle.Fixed) |
209 | - | Key.Encoding -> Encoding (Some Encoding.Raw) |
210 | + | `StateDir -> String (Some (Filename.concat base_xdg_share_path "/note")) |
211 | + | `LockFile -> String (Some (Filename.concat base_xdg_share_path "/note")) |
212 | + | `Editor -> String (Sys.getenv "EDITOR") |
213 | + | `OnModification -> String None |
214 | + | `ListStyle -> ListStyle (Some `Fixed) |
215 | + | `Encoding -> Encoding (Some `Raw) |
216 | |
217 | let value_of_string key s = |
218 | match key with |
219 | - | Key.StateDir -> String (Some s) |
220 | - | Key.LockFile -> String (Some s) |
221 | - | Key.Editor -> String (Some s) |
222 | - | Key.OnModification -> String (Some s) |
223 | - | Key.ListStyle -> ListStyle (Some (ListStyle.of_string s)) |
224 | - | Key.Encoding -> Encoding (Some (Encoding.of_string s)) |
225 | + | `StateDir -> String (Some s) |
226 | + | `LockFile -> String (Some s) |
227 | + | `Editor -> String (Some s) |
228 | + | `OnModification -> String (Some s) |
229 | + | `ListStyle -> ListStyle (Some (ListStyle.of_string s)) |
230 | + | `Encoding -> Encoding (Some (Encoding.of_string s)) |
231 | |
232 | let value_to_string value = |
233 | match value with |
234 | @@ -135,7 +135,7 @@ let load = |
235 | Yaml.of_string_exn (In_channel.read_all config_path) |
236 | in |
237 | |
238 | - let state_dir = get_string cfg Key.StateDir in |
239 | + let state_dir = get_string cfg `StateDir in |
240 | match Sys.file_exists state_dir with |
241 | | `Yes -> cfg |
242 | | `No | `Unknown -> |
243 | diff --git a/lib/config.mli b/lib/config.mli |
244 | index dc4d3b2..47f088e 100644 |
245 | --- a/lib/config.mli |
246 | +++ b/lib/config.mli |
247 | @@ -1,7 +1,7 @@ |
248 | open Base |
249 | |
250 | module ListStyle : sig |
251 | - type t = Fixed | Wide | Simple |
252 | + type t = [`Fixed | `Wide | `Simple] |
253 | |
254 | val of_string : string -> t |
255 | |
256 | @@ -9,7 +9,7 @@ module ListStyle : sig |
257 | end |
258 | |
259 | module Encoding : sig |
260 | - type t = Json | Yaml | Raw |
261 | + type t = [`Json | `Yaml | `Raw] |
262 | |
263 | val of_string : string -> t |
264 | |
265 | @@ -17,13 +17,13 @@ module Encoding : sig |
266 | end |
267 | |
268 | module Key : sig |
269 | - type t = |
270 | - | StateDir |
271 | - | LockFile |
272 | - | Editor |
273 | - | OnModification |
274 | - | ListStyle |
275 | - | Encoding |
276 | + type t = [ |
277 | + | `StateDir |
278 | + | `LockFile |
279 | + | `Editor |
280 | + | `OnModification |
281 | + | `ListStyle |
282 | + | `Encoding ] |
283 | |
284 | val all : t list |
285 |