From c698e20e1a8d0871662413b004a908f20bdb3960 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 25 Mar 2022 15:17:50 -0500 Subject: [bugfix] ecase error handling on bad ol command --- app/app.lisp | 175 ++++++++++++++++++++++++++++++----------------------------- 1 file changed, 89 insertions(+), 86 deletions(-) diff --git a/app/app.lisp b/app/app.lisp index 0684824..b0f845c 100644 --- a/app/app.lisp +++ b/app/app.lisp @@ -272,92 +272,95 @@ than the users." (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 (or (first args) "help"))) - (: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 - (help-and-quit-unless "run" id-or-name) - (cli:run-item id-or-name (rest args) - :verbose (getopt :long-name "verbose") - :confirm (getopt :long-name "confirm") - :timeout (getopt :long-name "timeout") - :draftp (getopt :long-name "draft"))) - (:clip - (help-and-quit-unless "clip" id-or-name) - (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" (= 2 (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))))))) + (handler-case + (ecase (a:make-keyword (string-upcase command)) + (:help + (princ #\newline) + (help-topic (or (first args) "help"))) + (: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 + (help-and-quit-unless "run" id-or-name) + (cli:run-item id-or-name (rest args) + :verbose (getopt :long-name "verbose") + :confirm (getopt :long-name "confirm") + :timeout (getopt :long-name "timeout") + :draftp (getopt :long-name "draft"))) + (:clip + (help-and-quit-unless "clip" id-or-name) + (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" (= 2 (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)))) + (#+sbcl sb-kernel:case-failure () + (help-topic "help")))))) (help-topic "help")) (#+sbcl sb-sys:interactive-interrupt #+ccl ccl:interrupt-signal-condition -- cgit v1.2.3