summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2015-08-15 23:14:17 -0400
committerDavid Thompson <dthompson2@worcester.edu>2015-08-15 23:14:17 -0400
commitabd946504ef1afa1ea77f84e9d76fb7fb0f2936a (patch)
treea35c545f702d3586a030ead71cb819973a39d093
parent08ed08da752e86011a5402e5f1282916614a1cb9 (diff)
ui: show: Extend to allow showing all keys of a secret.
* shroud/ui/show.scm (show-help): Remove --password help text. (%options): Remove --password option. (process-args): New procedure. (shroud-show): Rewrite.
-rw-r--r--shroud/ui/show.scm63
1 files changed, 31 insertions, 32 deletions
diff --git a/shroud/ui/show.scm b/shroud/ui/show.scm
index 6ad1ba0..84f0982 100644
--- a/shroud/ui/show.scm
+++ b/shroud/ui/show.scm
@@ -25,11 +25,9 @@
#:export (shroud-show))
(define (show-help)
- (format #t "Usage: shroud show [OPTION] id
+ (format #t "Usage: shroud show [OPTION] ID [KEY ...]
Show secret named ID.~%")
(display "
- -p, --password show only the password")
- (display "
-h, --help display this help and exit")
(display "
--version display version information and exit")
@@ -42,38 +40,39 @@ Show secret named ID.~%")
(exit 0)))
(option '("version") #f #f
(lambda args
- (show-version-and-exit)))
- (option '(#\p "password") #f #f
- (lambda (opt name arg result)
- (alist-cons 'password #t result)))))
+ (show-version-and-exit)))))
(define %default-options '())
-(define (shroud-show config db . args)
- (let* ((opts (args-fold args %options
- (lambda (opt name arg result)
- (leave "~A: unrecognized option" name))
- (lambda (arg result)
- (if (assq-ref result 'id)
- (leave "~A: extraneuous argument" arg)
- (alist-cons 'id arg result)))
- %default-options))
- (id (assq-ref opts 'id))
- (password? (assq-ref opts 'password)))
-
- (unless id
- (leave "no secret id specified"))
+(define (process-args args)
+ (args-fold args %options
+ (lambda (opt name arg result)
+ (leave "~A: unrecognized option" name))
+ (lambda (arg result)
+ (if (assq-ref result 'id)
+ (alist-cons 'key arg result)
+ (alist-cons 'id arg result)))
+ %default-options))
- (let* ((db (secrets-by-id (force db)))
- (secret (vhash-ref db id)))
- (unless secret
- (leave "~a: secret undefined" id))
+(define (shroud-show config db . args)
+ (let* ((opts (process-args args))
+ (id (leave-if-false (assq-ref opts 'id)
+ "No secret ID given"))
+ (keys (alist-pick opts 'key))
+ (secret (vhash-ref (secrets-by-id (force db)) id)))
- (if password?
- (display (secret-ref secret "password"))
- (format #t "username: ~a~%password: ~a~%"
- (secret-ref secret "username")
- (secret-ref secret "password")))))
+ (match keys
+ (()
+ (for-each (match-lambda
+ ((key . value)
+ (format #t "~a\t~a~%" key value)))
+ (secret-contents secret)))
+ ((keys ...)
+ (for-each (match-lambda
+ ((key . value)
+ (when (member key keys)
+ (format #t "~a~%" value))))
+ (secret-contents secret))))
- ;; We don't alter the database.
- db)
+ ;; Database remains unaltered.
+ db))