diff options
author | stuebinm | 2023-05-26 21:07:48 +0200 |
---|---|---|
committer | stuebinm | 2023-05-26 21:14:20 +0200 |
commit | e029a031050e08599f9d6d5fa654c17d985039c1 (patch) | |
tree | 3b4dd35bf6f6a8495b47ac5158a954151c9c0b55 /tools/obu-config | |
parent | 8737181eac0dce062ff0541e263ba0bf6a772c66 (diff) |
expose sequence length of trip to onboard unit
Diffstat (limited to 'tools/obu-config')
-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)) |