diff options
Diffstat (limited to '')
-rwxr-xr-x | tools/obu-config | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tools/obu-config b/tools/obu-config index 0cce2ee..d635834 100755 --- a/tools/obu-config +++ b/tools/obu-config @@ -16,14 +16,16 @@ give just the key to look something up Options: -s --statefile: state file + -d --delete: explicitly delete an entry -h --help: display this help -" progname)) +" progname progname)) (exit 0)) (define (main args) (let-args (cdr args) ((statefile "s|state=s") + (delete "d|delete") (help "h|help" => (cut show-help (car args))) . restargs) @@ -32,28 +34,32 @@ Options: "./obu-state.edn" statefile)) - (if (= (length restargs) 2) + (if (or delete (= (length restargs) 2)) (set file (list-ref restargs 0) - (list-ref restargs 1)) + (if delete #f (list-ref restargs 1)) + delete) (display (get file (list-ref restargs 0)))) (exit 0))) -(define (set file key value) +(define (set file key value delete) (define data (if (file-exists? file) (call-with-input-file file parse-edn) (edn-map))) (define data2 - (hashmap-set data (string->symbol key) value)) + (if delete + (hashmap-delete data (string->symbol key)) + (hashmap-set data (string->symbol key) value))) (call-with-output-file file (cut construct-edn data2 <>))) (define (get file key) (if (file-exists? file) - (hashmap-ref + (guard (e [else #f]) + (hashmap-ref (call-with-input-file file parse-edn) - (string->symbol key)) + (string->symbol key))) #f)) |