aboutsummaryrefslogtreecommitdiff
path: root/app/draft.lisp
diff options
context:
space:
mode:
Diffstat (limited to 'app/draft.lisp')
-rw-r--r--app/draft.lisp95
1 files changed, 95 insertions, 0 deletions
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 "<DRAFT>"
+ :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 "<DRAFT> [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 "<DRAFT>"
+ :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 "<DRAFT>"
+ :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)))