aboutsummaryrefslogtreecommitdiff
path: root/build-app.lisp
blob: c7f866736d25ded4ccb69aeb9f8d30026a6660fe (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
(asdf:load-system "oneliners.cli")

(defpackage #:oneliners.cli.app
  (:use #:cl #:net.didierverna.clon)
  (:local-nicknames (#:a #:alexandria)))

(in-package :oneliners.cli.app)

(defsynopsis (:postfix "TERMS ... | N ARGS ...")
  (text :contents "Search for oneliner mentioning TERMS or run the Nth search result with arguments ARGS.")
  (group (:header "Search")
         (lispobj :long-name "count" 
                  :argument-type :optional
                  :argument-name "Count"
                  :default-value 10
                  :description "The maximum number of results to return."
                  :typespec 'integer)
         (flag :long-name "not-flagged"
               :description "Request that no flagged oneliners are returned."))
  (group (:header "Wiki" :hidden t)
         (text :contents "This is text")
         (flag :long-name "add-interactive"
               :description  "Interactively add a new oneliner")
         (flag :long-name "update-interactive"
               :description "Interactively edit a oneliner and update the wiki."))
  (group (:header "Admin" :hidden t)
         (flag :long-name "invite"
               :description "Request an invite token to send to a friend.")
         (stropt :long-name "redeem"
                 :argument-type :optional
                 :default-value "DUMMY-TOKEN"
                 :argument-name "TOKEN"
                 :description "Redeem an invite token. Enter an
                 interactive process of setting up a new contributor
                 account with the inviting server"))
  (group (:header "Help")
         (flag :long-name "help" 
               :description "Print this help menu.")
         (enum :long-name "help-topic"
               :enum '(:admin :wiki :search :help)
               :argument-name "TOPIC"
               :description "Print help for a topic. Topics are: search, wiki, admin, help")))


(defun find-group-with-header (header)
  (loop for item in (net.didierverna.clon::items *synopsis*)
        when (and (typep item 'net.didierverna.clon::group)
                  (string-equal header (net.didierverna.clon::header item)))
          return item))


(defun main ()
  "Entry point for our standalone application."
  (make-context)
  (when (getopt :long-name "help")
    (help )
    (uiop:quit))

  (a:when-let (topic (getopt :long-name "help-topic"))
    (help :item (find-group-with-header (symbol-name topic)))
    (uiop:quit))

  (let ((arguments (remainder)))

    (unless arguments
      (help)
      (uiop:quit))

    (alexandria:when-let (hist-number (parse-integer (first arguments) :junk-allowed t))
      (format t "TBD: Going to run command ~a with arguments ~a~%"
              hist-number (rest arguments))
      (uiop:quit))

    (format t "TBD: Going to search for commands mentioning the terms ~a~%" arguments))

  (uiop:quit))


(dump "ol" main)