aboutsummaryrefslogtreecommitdiff
path: root/app/modify.lisp
blob: 5ad9655ef64a1c429dcf37afc35b6bb792e1f021 (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
;;;; modify.lisp

(in-package :oneliners.cli.app)

;; ol modify flag <ID>
;; ol modify unflag <ID>
;; ol modify description <ID> new description ...
;; ol modify redraft <ID>
;; ol modify name <ID> New-name
;; ol modify lock <ID>
;; ol modify unlock <ID>

(defhandler modify/redraft/handler (id)
  (ol:edit-item (parse-identifier id)))

(defun modify/redraft/command ()
  (cli:make-command
   :name "redraft"
   :usage "<IDENTIFIER>"
   :description "edit an existing oneliner"
   :handler #'modify/redraft/handler))

(defhandler modify/flag/handler (id)
  (ol::flag-item (parse-identifier id)))

(defun modify/flag/command ()
  (cli:make-command
   :name "flag"
   :usage "<IDENTIFIER>"
   :description "flag a oneliner as potentially wrong or hazardous"
   :handler #'modify/flag/handler))

(defhandler modify/unflag/handler (id)
  (ol::unflag-item (parse-identifier id)))

(defun modify/unflag/command ()
  (cli:make-command
   :name "unflag"
   :usage "<IDENTIFIER>"
   :description "remove flagged status from a oneliner"
   :handler #'modify/unflag/handler))

(defhandler modify/lock/handler (id)
  (ol::lock-item (parse-identifier id)))

(defun modify/lock/command ()
  (cli:make-command
   :name "lock"
   :usage "<IDENTIFIER>"
   :description "lock a oneliner from being changed (admin only)"
   :handler #'modify/lock/handler))

(defun modify/unlock/handler (id)
  (ol::unlock-item (parse-identifier id)))

(defun modify/unlock/command ()
  (cli:make-command
   :name "unlock"
   :usage "<IDENTIFIER>"
   :description "unlock a locked oneliner, allowing it to be modified again"
   :handler #'modify/unlock/handler))

(defun modify/delete/handler (id)
  (ol::delete-item (parse-identifier id)))

(defun modify/delete/command ()
  (cli:make-command
   :name "delete"
   :usage "<IDENTIFIER>"
   :description "delete a oneliner from the server."))

(defun modify/subcommands ()
  (list
   (modify/redraft/command)
   (modify/flag/command)
   (modify/unflag/command)
   (modify/lock/command)
   (modify/unlock/command)
   (modify/delete/command)))

(defun modify/handler (cmd)
  (cli:print-usage cmd t))

(defun modify/command ()
  (cli:make-command
   :name "modify"
   :description "alter an existing oneliner"
   :handler #'modify/handler
   :sub-commands (modify/subcommands)))