Improve help messages
The `help' command can now be used to view help about other commands.
This commit is contained in:
parent
cbe1830f83
commit
c7f9d27638
1 changed files with 45 additions and 16 deletions
|
@ -30,17 +30,17 @@
|
||||||
(defvar *max-command-name-length* 0
|
(defvar *max-command-name-length* 0
|
||||||
"Lenght of the longest command name.")
|
"Lenght of the longest command name.")
|
||||||
|
|
||||||
(defmacro defcommand (name doc &body body)
|
(defmacro defcommand (name sdoc ldoc &body body)
|
||||||
"Define a new command usable on the command-line."
|
"Define a new command usable on the command-line."
|
||||||
(let* ((sname (symbol-name name))
|
(let* ((sname (symbol-name name))
|
||||||
(command-name (make-command-name sname)))
|
(command-name (make-command-name sname)))
|
||||||
`(progn
|
`(progn
|
||||||
(defun ,command-name (args)
|
(defun ,command-name (args)
|
||||||
,doc
|
,sdoc
|
||||||
,@body)
|
,@body)
|
||||||
(setf *help-messages*
|
(setf *help-messages*
|
||||||
(nconc *help-messages*
|
(nconc *help-messages*
|
||||||
'((,(string-downcase sname) ,doc "")))
|
'((,(string-downcase sname) ,sdoc ,ldoc)))
|
||||||
*max-command-name-length*
|
*max-command-name-length*
|
||||||
(max *max-command-name-length* (length ,sname))))))
|
(max *max-command-name-length* (length ,sname))))))
|
||||||
|
|
||||||
|
@ -88,6 +88,22 @@ The result contains the url and the name of the bookmark."
|
||||||
"Get the rowid of tag NAME."
|
"Get the rowid of tag NAME."
|
||||||
(execute-single *db* "SELECT rowid FROM tag WHERE name = ?" name))
|
(execute-single *db* "SELECT rowid FROM tag WHERE name = ?" name))
|
||||||
|
|
||||||
|
(defun help-message ()
|
||||||
|
(format t (concatenate
|
||||||
|
'string
|
||||||
|
"Usage: clark [<command> [<options> ...]]~%"
|
||||||
|
"~%"
|
||||||
|
"Possible commands:~%"
|
||||||
|
"~%"))
|
||||||
|
(map nil (lambda (hlp)
|
||||||
|
(destructuring-bind (name short long) hlp
|
||||||
|
(declare (ignore long))
|
||||||
|
(format t " ~vA ~A~%" *max-command-name-length*
|
||||||
|
name short))) *help-messages*)
|
||||||
|
(format t "~%~A~%"
|
||||||
|
(concatenate 'string "Use `clark help <command>' to get more "
|
||||||
|
"information on a command.")))
|
||||||
|
|
||||||
(defun insert-bookmark (url name description)
|
(defun insert-bookmark (url name description)
|
||||||
"Insert URL, NAME and DESCRIPTION into the bookmark table."
|
"Insert URL, NAME and DESCRIPTION into the bookmark table."
|
||||||
(execute-non-query *db* "INSERT INTO bookmark VALUES (?, ?, ?, ?)"
|
(execute-non-query *db* "INSERT INTO bookmark VALUES (?, ?, ?, ?)"
|
||||||
|
@ -135,6 +151,10 @@ BM should be a list containing the url and name of the bookmark."
|
||||||
|
|
||||||
(defcommand add
|
(defcommand add
|
||||||
"Add a new bookmark."
|
"Add a new bookmark."
|
||||||
|
"Usage: clark add <url> <name> <description> [<tags> ...]
|
||||||
|
|
||||||
|
Add URL with NAME, DESCRIPTION and TAGS to the database. TAGS may be
|
||||||
|
omitted or any number of tag names."
|
||||||
(with-transaction *db*
|
(with-transaction *db*
|
||||||
(destructuring-bind (url name description &rest tags) args
|
(destructuring-bind (url name description &rest tags) args
|
||||||
(insert-bookmark url name description)
|
(insert-bookmark url name description)
|
||||||
|
@ -142,6 +162,10 @@ BM should be a list containing the url and name of the bookmark."
|
||||||
|
|
||||||
(defcommand exists
|
(defcommand exists
|
||||||
"Check if a bookmark exists in the database."
|
"Check if a bookmark exists in the database."
|
||||||
|
"Usage: clark exists <url>
|
||||||
|
|
||||||
|
Check if URL exists in the database. Prints `yes' when found and `no'
|
||||||
|
otherwise."
|
||||||
(if (execute-single *db* "SELECT rowid FROM bookmark WHERE url = ?"
|
(if (execute-single *db* "SELECT rowid FROM bookmark WHERE url = ?"
|
||||||
(car args))
|
(car args))
|
||||||
(progn
|
(progn
|
||||||
|
@ -153,22 +177,24 @@ BM should be a list containing the url and name of the bookmark."
|
||||||
|
|
||||||
(defcommand help
|
(defcommand help
|
||||||
"Show help message."
|
"Show help message."
|
||||||
(declare (ignore args))
|
help-message
|
||||||
(format t (concatenate
|
(if (> (length args) 0)
|
||||||
'string
|
(let ((ldoc
|
||||||
"Usage: clark [<command> [<options> ...]]~%"
|
(nth 2 (car (member
|
||||||
" clark add <url> <name> <description> [<tags> ...]~%"
|
(car args) *help-messages*
|
||||||
"~%"
|
:test #'(lambda (x y) (equal x (car y))))))))
|
||||||
"Possible commands:~%"
|
(cond
|
||||||
"~%"))
|
((null ldoc) (format t "Unkown command: ~A~%" (car args)))
|
||||||
(map nil (lambda (hlp)
|
((and (symbolp ldoc) (fboundp ldoc)) (funcall ldoc))
|
||||||
(destructuring-bind (name short long) hlp
|
(t (format t "~A~%" ldoc))))
|
||||||
(declare (ignore long))
|
(help-command '("help"))))
|
||||||
(format t " ~vA ~A~%" *max-command-name-length*
|
|
||||||
name short))) *help-messages*))
|
|
||||||
|
|
||||||
(defcommand search
|
(defcommand search
|
||||||
"Search through bookmarks."
|
"Search through bookmarks."
|
||||||
|
"Usage: clark search <str>
|
||||||
|
|
||||||
|
Search the database for STR. Matches are made for substrings of a
|
||||||
|
bookmark's name or an exact match for a tag."
|
||||||
(map
|
(map
|
||||||
nil (lambda (bm)
|
nil (lambda (bm)
|
||||||
(destructuring-bind (url name description) bm
|
(destructuring-bind (url name description) bm
|
||||||
|
@ -186,6 +212,9 @@ BM should be a list containing the url and name of the bookmark."
|
||||||
|
|
||||||
(defcommand version
|
(defcommand version
|
||||||
"Show version."
|
"Show version."
|
||||||
|
"Usage: clark version
|
||||||
|
|
||||||
|
Print the version number and exit."
|
||||||
(declare (ignore args))
|
(declare (ignore args))
|
||||||
(format t "clark version ~A~%" *version*))
|
(format t "clark version ~A~%" *version*))
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue