From 13665db59e8b0467343eba53ee56873465034ec3 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 4 Mar 2022 13:37:22 -0600 Subject: explicitly run by id or name, removed numbered history --- build-app.lisp | 62 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 28 deletions(-) (limited to 'build-app.lisp') diff --git a/build-app.lisp b/build-app.lisp index 3511a8c..a3ef6fc 100644 --- a/build-app.lisp +++ b/build-app.lisp @@ -62,8 +62,6 @@ you run the oneliner, all positional variables appear first. ;;; CLON SYNOPSIS DEFINITION (defsynopsis (:postfix "[ARGUMENTS ...]") - - (group (:header "SEARCH OPTIONS") (text :contents "By default, ARGUMENTS are interpeted as search terms for oneliners. For example:") (text :contents "$ ol grep awk # search for oneliners involving both grep and awk") @@ -82,15 +80,11 @@ you run the oneliner, all positional variables appear first. (flag :long-name "newest" :description "Return newest oneliners.")) (text :contents " ") - - (group (:header "EXECUTION OPTIONS") (text :contents "Several options override the default interpretation of ARGUMENTS.") (text :contents "Execution options interpret the first argument as the identifier of a oneliner: ") (text :contents "$ ol [MORE ARGUMENTS...]") (text :contents " ") - - (flag :long-name "run" :description "Executes a oneliner by NAME or ID. See also help topic 'variables'.") (flag :long-name "clip" @@ -111,11 +105,9 @@ you run the oneliner, all positional variables appear first. :description "View information about a contributor. The first argument is a contributor handle.") (flag :long-name "help" :description "Print help for a topic. Topics: wiki, account, invites, variables")) - (group (:header "Advanced Options" :hidden t) (flag :long-name "clear-cache" :description "Clears all cached search results from your system.")) - (group (:header "Variables" :hidden t) (text :contents +oneliners-variables-help-text+)) (group (:header "Wiki" :hidden t) @@ -166,6 +158,14 @@ than the users." ;;; MAIN ENTRY POINT +(defun prepare-oneliner-arguments (arguments) + "Takes a list of arguments, as gathered by (REMAINDER), and returns + a list that looks like (ID-OR-NAME . ARGS) where ID-OR-NAME is + either an integer or a string." + (a:if-let (id (parse-integer (first arguments) :junk-allowed t)) + (cons id (rest arguments)) + arguments)) + (defun main () "Entry point for our standalone application." (make-context) @@ -176,18 +176,21 @@ than the users." (let ((arguments (remainder))) (cond ((getopt :long-name "whois") - (assert (first arguments)) + (assert (first arguments) () "--whois requires an argument, a user handle.") (cli::show-contributor (first arguments))) ((getopt :long-name "redeem") + (assert (= 3 (length arguments)) () "--redeem requires exatly three arguments.") (destructuring-bind (token name pass) arguments (cli::redeem-invite token name pass))) ((getopt :long-name "login") + (assert (= 2 (length arguments)) () "--login requires exactly two arguments.") (destructuring-bind (user pass) arguments (cli::login user pass))) ((getopt :long-name "change-password") + (assert (= 3 (length arguments)) () "--change-password requires exactly three arguments." ) (destructuring-bind (current new repeated) arguments (cli::change-pw current new repeated))) @@ -204,40 +207,43 @@ than the users." (cli::add-new-oneliner)) ((getopt :long-name "all-flagged") + (format t "WARNING: --all-flagged is likely to soon change its behavior~%.") (cli::all-flagged-oneliners (getopt :long-name "limit"))) ((getopt :long-name "newest") + (format t "WARNING: --newest is likely to soon change its behavior~%") (cli::newest-oneliners (getopt :long-name "limit"))) ((getopt :long-name "clear-cache") (cli::wipe-cache)) (arguments - ;; when the first argument is a number, try run a oneliner - (a:when-let (hist-number (parse-integer (first arguments) :junk-allowed t)) + (destructuring-bind (id-or-name . args) (prepare-oneliner-arguments arguments) (cond ((getopt :long-name "flag") - (cli::flag-item hist-number (getopt :long-name "id"))) + (cli::flag-item id-or-name )) ((getopt :long-name "unflag") - (cli::unflag-item hist-number (getopt :long-name "id"))) + (cli::unflag-item id-or-name)) ((getopt :long-name "lock") - (cli::lock-item hist-number (getopt :long-name "id"))) + (cli::lock-item id-or-name )) ((getopt :long-name "unlock") - (cli::unlock-item hist-number (getopt :long-name "id"))) + (cli::unlock-item id-or-name )) ((getopt :long-name "edit") - (cli::edit-item hist-number (getopt :long-name "id"))) - ((getopt :long-name "explain") - (cli::print-item-explanation hist-number (getopt :long-name "id"))) - (t - (cli::run-item hist-number (rest arguments) - :by-id (getopt :long-name "id") - :force-clip (getopt :long-name "clip") - :timeout (getopt :long-name "timeout")))) - (uiop:quit)) - ;; otherwise search for oneliners - (cli::search-for-oneliners arguments - (getopt :long-name "limit") - (getopt :long-name "not-flagged"))) + (cli::edit-item id-or-name )) + ((getopt :long-name "info") + (cli::print-item-explanation id-or-name)) + ((getopt :long-name "clip") + (cli::run-item id-or-name (rest arguments) + :force-clip t + :timeout (getopt :long-name "timeout"))) + ((getopt :long-name "run") + (cli::run-item id-or-name (rest arguments) + :timeout (getopt :long-name "timeout"))) + (t + (cli::search-for-oneliners arguments + (getopt :long-name "limit") + (getopt :long-name "not-flagged"))))) + (uiop:quit)) (t (help))) (uiop:quit)) -- cgit v1.2.3