From e029a031050e08599f9d6d5fa654c17d985039c1 Mon Sep 17 00:00:00 2001 From: stuebinm Date: Fri, 26 May 2023 21:07:48 +0200 Subject: expose sequence length of trip to onboard unit --- tools/obu-config | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'tools/obu-config') 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)) -- cgit v1.2.3