aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Tom Willemsen2012-12-29 02:21:21 +0100
committerGravatar Tom Willemsen2012-12-29 02:21:21 +0100
commit27bdb9bdd130a91ed5dff6c973e6ba862e44fd1b (patch)
tree168add2d9f2ad53e21bb1a44dc0d3c890471b091 /src
parent71e54b6a61f538bff294e94e8484e524592664d0 (diff)
downloadmarkam-27bdb9bdd130a91ed5dff6c973e6ba862e44fd1b.tar.gz
markam-27bdb9bdd130a91ed5dff6c973e6ba862e44fd1b.zip
Add version and help options to linkwave
Diffstat (limited to 'src')
-rw-r--r--src/linkwave.scm42
1 files changed, 35 insertions, 7 deletions
diff --git a/src/linkwave.scm b/src/linkwave.scm
index fbb25fd..12a2a9b 100644
--- a/src/linkwave.scm
+++ b/src/linkwave.scm
@@ -26,6 +26,8 @@
(require-extension sqlite3)
(require-library posix srfi-4)
+(define version "0.1.0")
+
(: string-no-null (string -> string))
(define (string-no-null str)
;; If STR contains a \0 byte at the end, remove it, otherwise return
@@ -74,19 +76,45 @@
(or (string= (substring str 0 7) "http://")
(string= (substring str 0 8) "https://"))))
+(define (display-version)
+ ;; Display linkwave's version number.
+ (format #t "linkwave v~a~%" version))
+
+(define (display-help)
+ ;; Display linkwave's help message.
+ (format #t (string-append
+ "Usage: linkwave [options]...~%"
+ " linkwave <url> <name> <description> [<tag>...]~%"
+ "~%"
+ "Possible options:~%"
+ "~%"
+ "--help, -h Display this help and exit~%"
+ "--version, -v Output version information and exit~%")))
+
(define (main args)
;; Open a database connection, do what the user asked and close it
;; again.
(let ((db (open-database (data-file "linkwave.db"))))
(if (null? args)
(for-each-row print-row db "select * from bookmark")
- (cond
- ((url-string? (car args))
- (with-transaction
- db (lambda () (add-bookmark db (car args) (cadr args) (caddr args) (cdddr args)) #t)))
- (else
- (format #t "Unrecognized option: ~a~%" (car args)))))
-
+ (if (url-string? (car args))
+ (with-transaction
+ db (lambda () (add-bookmark db (car args) (cadr args) (caddr args) (cdddr args)) #t))
+ ;; If the first argument is not a URL, loop through all
+ ;; arguments and proceed accordingly.
+ (do ((arg (car args) (and (not (null? args))
+ (car args))))
+ ((or (null? arg) (not arg)))
+ (cond
+ ((or (string= arg "-v") (string= arg "--version"))
+ (display-version)
+ (exit 0))
+ ((or (string= arg "-h") (string= arg "--help"))
+ (display-help)
+ (exit 0))
+ (else
+ (format #t "Unrecognized option: ~a~%" (car args))))
+ (set! args (cdr args)))))
(finalize! db #t)))
(main (command-line-arguments))