From f116178dcf8b450c76400e2a0fbd2991f2c227b4 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Fri, 5 Aug 2022 08:58:35 -0500 Subject: [wip] [refactor] [add] subcommands. --- app/draft.lisp | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 app/draft.lisp (limited to 'app/draft.lisp') diff --git a/app/draft.lisp b/app/draft.lisp new file mode 100644 index 0000000..ea71e49 --- /dev/null +++ b/app/draft.lisp @@ -0,0 +1,95 @@ +;;;; draft.lisp + +(in-package :oneliners.cli.app) + +(defun draft/new/handler (cmd) + (ol:add-new-oneliner)) + +(defun draft/new/command () + (cli:make-command + :name "new" + :description "interactively draft a new oneliner" + :handler #'draft/new/handler)) + + +(defun draft/publish/handler (cmd) + (a:if-let (name (first (cli:command-arguments cmd))) + (ol::publish-draft name) + (cli:print-usage-and-exit cmd t))) + +(defun draft/publish/command () + (cli:make-command + :name "publish" + :usage "" + :description "publish draft to the server" + :handler #'draft/publish/handler)) + +(defun draft/test/handler (cmd) + (a:if-let (args (cli:command-arguments cmd)) + (ol:run-item (first args) (rest args) + :verbose (cli:getopt cmd :verbose) + :confirm (cli:getopt cmd :confirm) + :timeout (cli:getopt cmd :timeout) + :draftp t) + (cli:print-usage-and-exit cmd t))) + +(defun draft/test/command () + (cli:make-command + :name "test" + :usage " [ARG ...]" + :description "runs a draft oneliner, same options as `ol run`" + :options (run/options) + :handler #'draft/new/handler)) + +(defun draft/edit/handler (cmd) + (a:if-let (name (first (cli:command-arguments cmd))) + (ol:edit-item name t) + (cli:print-usage-and-exit cmd t))) + +(defun draft/edit/command () + (cli:make-command + :name "edit" + :usage "" + :description "interactively edits a draft" + :handler #'draft/edit/handler)) + +(defun draft/trash/handler (cmd) + (a:if-let (name (first (cli:command-arguments cmd))) + (ol::drop-draft name) + (cli:print-usage-and-exit cmd t))) + +(defun draft/trash/command () + (cli:make-command + :name "trash" + :usage "" + :description "trash a draft" + :handler #'draft/trash/handler)) + +(defun draft/list/handler (cmd) + (declare (ignore cmd)) + (ol::print-drafts)) + +(defun draft/list/command () + (cli:make-command + :name "list" + :description "list drafted oneliners" + :handler #'draft/list/handler)) + +(defun draft/subcommands () + (list + (draft/new/command) + (draft/publish/command) + (draft/test/command) + (draft/edit/command) + (draft/trash/command) + (draft/list/command))) + +(defun draft/handler (cmd) + (cli:print-usage-and-exit cmd t)) + +(defun draft/command () + (cli:make-command + :name "draft" + :description "draft, test, and publish new oneliners" + :handler #'draft/command + :sub-commands (draft/subcommands))) -- cgit v1.2.3