aboutsummaryrefslogtreecommitdiff
path: root/app/run.lisp
blob: 556b719e1f76b3154d32f00c4925a6d7f4437dc2 (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
;;;; run.lisp -- run a command

(in-package :oneliners.cli.app)

(defun run/options ()
  (list
   (make-option
    :integer
    :short-name #\t
    :long-name "timeout"
    :key :timeout
    :initial-value 1
    :description "Seconds to wait for output before giving up.")
   (make-option
    :flag
    :short-name #\v
    :long-name "verbose"
    :key :verbose
    :description "echoes the oneliner text that is about to be run")
   (make-option
    :flag
    :short-name #\c
    :long-name "confirm"
    :key :confirm
    :description "prompts the user for confirmation before running the command")))

(defhandler run/handler (id . args)
  (ol:run-item (parse-identifier id) args
               :verbose (cli:getopt *cmd* :verbose)
               :confirm (cli:getopt *cmd* :confirm)
               :timeout (cli:getopt *cmd* :timeout)))

(defparameter +run/examples+
  '(("Run a hypothetical command called echo-stuff with positional arguments" .
     "ol run echo-stuff one two three")
    ("Run a hypothetical command with id 341 with a timeout and confirmation" .
     "ol run -c -t 10 341")))

(defun run/command ()
  (cli:make-command
   :name "run"
   :usage "<IDENTIFIER> [ARG ...]"
   :description "run the identified oneliner with any arguments it might take"
   :options (run/options)
   :handler #'run/handler
   :examples +run/examples+))