aboutsummaryrefslogtreecommitdiff
path: root/app/app.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'app/app.lisp')
-rw-r--r--app/app.lisp171
1 files changed, 97 insertions, 74 deletions
diff --git a/app/app.lisp b/app/app.lisp
index bac6628..25ac8d7 100644
--- a/app/app.lisp
+++ b/app/app.lisp
@@ -187,6 +187,7 @@ export EDITOR=/usr/bin/zile
(text :contents "show")
(text :contents "new")
(text :contents "edit")
+ (text :contents "delete")
(text :contents "drafts")
(text :contents "trash")
(text :contents "publish")
@@ -195,6 +196,7 @@ export EDITOR=/usr/bin/zile
(text :contents "redeem")
(text :contents "invite")
(text :contents "login")
+ (text :contents "whois")
(text :contents "password")
(text :contents "signature")))
@@ -214,80 +216,101 @@ than the users."
;;; MAIN ENTRY POINT
(defun main ()
- (make-context)
- (a:if-let (arguments (remainder))
- (destructuring-bind (command . args) arguments
- (let ((id-or-name
- (when args
- (or (parse-integer (first args) :junk-allowed t)
- (first args)))))
- (cli:with-local-state
- (ecase (a:make-keyword (string-upcase command))
- (:help
- (princ #\newline)
- (help-topic (first args)))
- (:search
- (cli:search-for-oneliners
- args
- (getopt :long-name "limit")
- (getopt :long-name "not-flagged")
- (getopt :long-name "all-flagged")
- (getopt :long-name "newest")))
- (:run
- (cli:run-item id-or-name (rest args)
- :timeout (getopt :long-name "timeout")
- :draftp (getopt :long-name "draft")))
- (:clip
- (cli:run-item id-or-name (rest args)
- :force-clip t
- :draftp (getopt :long-name "draft")))
- (:show
- (cli:print-item-explanation id-or-name))
- (:new
- (cli:add-new-oneliner))
- (:edit
- (cli:edit-item id-or-name (getopt :long-name "redraft")))
- (:publish
- (cli::publish-draft id-or-name))
- (:trash
- (cli::drop-draft id-or-name))
- (:drafts
- (cli::print-drafts))
- (:flag
- (cli:flag-item id-or-name))
- (:unflag
- (cli:unflag-item id-or-name))
- (:lock
- (cli:lock-item id-or-name))
- (:unlock
- (cli:unlock-item id-or-name))
- (:redeem
- (unless (= 3 (length args))
- (help-topic "redeem")
- (uiop:quit))
- (apply 'cli:redeem-invite args))
- (:invite
- (cli:request-invite-code))
- (:login
- (unless (= 3 (length args))
- (help-topic "login")
- (uiop:quit))
- (apply 'cli:login args))
- (:logout
- (cli:revoke-access))
- (:password
- (unless (= 3 (length args))
- (help-topic "password")
- (uiop:quit))
- (apply 'cli:change-pw args))
- (:signature
- (cli:change-signature))
- (:whois
- (unless args
- (help-topic "whois")
- (uiop:quit))
- (cli:show-contributor (first args)))))))
- (help))
+ (macrolet ((help-and-quit-unless (topic check)
+ `(unless ,check
+ (help-topic ,topic)
+ (uiop:quit))))
+ (make-context)
+ (a:if-let (arguments (remainder))
+ (destructuring-bind (command . args) arguments
+ (let ((id-or-name
+ (when args
+ (or (parse-integer (first args) :junk-allowed t)
+ (first args)))))
+ (cli:with-local-state
+ (ecase (a:make-keyword (string-upcase command))
+ (:help
+ (princ #\newline)
+ (help-topic (first args)))
+ (:search
+ (cond
+ ;; if there are args, use them as search terms
+ (args
+ (cli:search-for-oneliners
+ args
+ (getopt :long-name "limit")
+ (getopt :long-name "not-flagged")
+ (getopt :long-name "all-flagged")
+ (getopt :long-name "newest")))
+ ;; no args, but a --newest flag, just return newest
+ ((getopt :long-name "newest")
+ (cli::newest-oneliners (getopt :long-name "limit")))
+ ;; no args, but a --all-falgged
+ ((getopt :long-name "all-flagged")
+ (cli::all-flagged-oneliners (getopt :long-name "limit")))
+ ;; otherwise, print help for search
+ (t
+ (help-topic "search")
+ (uiop:quit))))
+
+ (:run
+ (cli:run-item id-or-name (rest args)
+ :timeout (getopt :long-name "timeout")
+ :draftp (getopt :long-name "draft")))
+ (:clip
+ (cli:run-item id-or-name (rest args)
+ :force-clip t
+ :draftp (getopt :long-name "draft")))
+ (:show
+ (help-and-quit-unless "show" id-or-name)
+ (cli:print-item-explanation id-or-name))
+ (:new
+ (cli:add-new-oneliner))
+ (:edit
+ (help-and-quit-unless "edit" id-or-name)
+ (cli:edit-item id-or-name (getopt :long-name "redraft")))
+ (:delete
+ (help-and-quit-unless "delete" id-or-name)
+ (cli::delete-item id-or-name))
+ (:publish
+ (help-and-quit-unless "publish" id-or-name)
+ (cli::publish-draft id-or-name))
+ (:trash
+ (help-and-quit-unless "trash" id-or-name)
+ (cli::drop-draft id-or-name))
+ (:drafts
+ (cli::print-drafts))
+ (:flag
+ (help-and-quit-unless "flag" id-or-name)
+ (cli:flag-item id-or-name))
+ (:unflag
+ (help-and-quit-unless "flag" id-or-name)
+ (cli:unflag-item id-or-name))
+ (:lock
+ (help-and-quit-unless "lock" id-or-name)
+ (cli:lock-item id-or-name))
+ (:unlock
+ (help-and-quit-unless "lock" id-or-name)
+ (cli:unlock-item id-or-name))
+ (:redeem
+ (help-and-quit-unless "redeem" (= 3 (length args)))
+ (apply 'cli:redeem-invite args))
+ (:invite
+ (cli:request-invite-code))
+ (:login
+ (help-and-quit-unless "login" (= 3 (length args)))
+ (apply 'cli:login args))
+ (:logout
+ (cli:revoke-access))
+ (:password
+ (help-and-quit-unless "password" (= 3 (length args)))
+ (apply 'cli:change-pw args))
+ (:signature
+ (cli:change-signature))
+ (:whois
+ (help-and-quit-unless "whois" args)
+ (cli:show-contributor (first args)))))))
+ (help)))
(uiop:quit))
(defun help-topic (topic)