aboutsummaryrefslogtreecommitdiff
path: root/app/draft.lisp
blob: ea71e491c1f01d60749194ec20a09ca3332223e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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)))