git.fiddlerwoaroof.com
Browse code

Add basic self-configuration

fiddlerwoaroof authored on 09/05/2016 03:48:28
Showing 3 changed files
... ...
@@ -6,7 +6,7 @@
6 6
   (apply #'format stream prompt args)
7 7
   (force-output stream)
8 8
   (read-line stream nil :done))
9
-(trace prompt-for-line)
9
+;(trace prompt-for-line)
10 10
 
11 11
 (defun prompt-for-lines (stream initial-prompt continuation-prompt &rest args)
12 12
   "Not finished ... see :description below"
... ...
@@ -47,3 +47,10 @@
47 47
         do (vector-push-extend trim-line lines)
48 48
         finally (return (string-join lines #\newline))))
49 49
 
50
+(defmethod prompt ((field-name (eql :jira-account)) &optional (stream *prompt-stream*))
51
+  (prompt-for-line stream "JIRA Subdomain? "))
52
+
53
+(defmethod prompt ((field-name (eql :creds)) &optional (stream *prompt-stream*))
54
+  (let ((username (prompt-for-line stream "Username? "))
55
+        (password (prompt-for-line stream "Password (visible)? ")))
56
+    (list username password)))
... ...
@@ -36,6 +36,34 @@
36 36
   (declare (ignore args))
37 37
   (format nil "~a" (name status)))
38 38
 
39
+(defun show-description (description)
40
+  (pprint-logical-block (*standard-output* (mapcar (compose 'tokens 'trim-whitespace)
41
+                                                 (lines description)))
42
+    (pprint-indent :block 4 *standard-output*)
43
+    (pprint-newline :mandatory *standard-output*)
44
+    (loop
45
+      (pprint-exit-if-list-exhausted)
46
+      (let ((line (pprint-pop)))
47
+        (pprint-logical-block (*standard-output* line)
48
+          (loop
49
+            (princ (pprint-pop) *standard-output*)
50
+            (pprint-exit-if-list-exhausted)
51
+            (princ #\space *standard-output*)
52
+            (pprint-indent :block 3)
53
+            (pprint-newline :fill *standard-output*)))
54
+        (pprint-newline :mandatory *standard-output*)))))
55
+
56
+(defun show-summary (summary)
57
+  (pprint-logical-block (*standard-output* (funcall (compose 'tokens 'trim-whitespace) summary))
58
+    (pprint-indent :block 8 *standard-output*)
59
+    (pprint-exit-if-list-exhausted)
60
+    (format *standard-output* "~4tSummary: ")
61
+    (loop
62
+      (princ (pprint-pop))
63
+      (pprint-exit-if-list-exhausted)
64
+      (pprint-newline :fill *standard-output*)
65
+      (princ #\space))))
66
+
39 67
 (sheeple:defreply show ((issue =issue=) &rest args)
40 68
   (declare (ignorable args))
41 69
   (with-output-to-string (*standard-output*)
... ...
@@ -68,7 +96,6 @@
68 96
 (sheeple:defproto =issuetype= () (description name))
69 97
 
70 98
 (sheeple:defreply sheeple:shared-init :after ((project =project=) &key)
71
-                  (declare (optimize (debug 3)))
72 99
   (with-accessors ((issuetypes issuetypes)) project
73 100
     (when issuetypes
74 101
       (map nil
... ...
@@ -12,7 +12,7 @@
12 12
   (:use #:cl #:serapeum #:alexandria #:fw.lu #:jira-api.cli #:jira-api #:net.didierverna.clon))
13 13
 
14 14
 (in-package #:jira-api.client)
15
-(defparameter *version* (format nil "0.1-init")) 
15
+(defparameter *version* (format nil "0.1-init"))
16 16
 
17 17
 (defparameter *endpoint-template* "https://~a.atlassian.net/rest/api/2/")
18 18
 
... ...
@@ -30,8 +30,9 @@
30 30
          (flag :short-name "i"
31 31
                :long-name "get-issue"
32 32
                :description "show an issue")
33
-         (flag :short-name "pi" :long-name "post-issue"
34
-               :description "post and issue"))
33
+         ;(flag :short-name "pi" :long-name "post-issue"
34
+         ;      :description "post and issue")
35
+         )
35 36
   (group (:header "JIRA options")
36 37
          (stropt :long-name "jira-account"
37 38
                  :description "The jira account to use."
... ...
@@ -41,22 +42,37 @@
41 42
          (stropt :short-name "s" :long-name "status"
42 43
                  :description "Only show issues with a certain status"))
43 44
   (group (:header "Other options")
45
+         (flag :short-name "dc" :long-name "dump-configuration"
46
+               :description "Dump the current configuration")
47
+         (flag :short-name "g" :long-name "configure"
48
+               :description "Configure the default values")
44 49
          (flag :short-name "h" :long-name "help"
45
-               :description "Show this help") 
50
+               :description "Show this help")
46 51
          (flag :short-name "v" :long-name "version"
47 52
                :description "Show the program version")))
48 53
 
49 54
 (defvar *auth*)
50 55
 
56
+(defun dump-configuration ()
57
+  (format t "~&~s~&"
58
+          (hash-table-alist
59
+            (ubiquitous:value :jira))))
60
+
51 61
 (defun main ()
52
-  (ubiquitous:restore :jira-api) 
62
+  (ubiquitous:restore :jira-api)
53 63
   (setf *auth* (ubiquitous:value :jira :creds))
54 64
   (make-context)
55
-  
65
+
56 66
   (let ((jira-api::*endpoint* (format nil *endpoint-template* (getopt :long-name "jira-account"))))
57 67
     (cond
58 68
       ((getopt :long-name "help") (help))
59 69
       ((getopt :long-name "version") (format t "~&~a~%" *version*))
70
+      ((getopt :long-name "dump-configuration") (dump-configuration))
71
+      ((getopt :long-name "configure") (let ((creds (prompt :creds))
72
+                                             (account (prompt :jira-account)))
73
+                                         (setf (ubiquitous:value :jira :creds) creds)
74
+                                         (setf (ubiquitous:value :jira :account) account)
75
+                                         (dump-configuration)))
60 76
       ((getopt :long-name "get-issue") (let ((options (remainder)))
61 77
                                          (format t "~&~a~&"
62 78
                                                  (jira-api::show
... ...
@@ -70,7 +86,7 @@
70 86
        (let ((options (remainder)))
71 87
          (let ((issues (jira-api::json2sheeple (jira-api::get-issues *auth*))))
72 88
            (alexandria:if-let ((status (getopt :long-name "status")))
73
-             (setf issues 
89
+             (setf issues
74 90
                    (sheeple:defobject ()
75 91
                                       ((jira-api::issues
76 92
                                          (apply 'vector
... ...
@@ -81,9 +97,6 @@
81 97
                                              (jira-api::json2sheeple
82 98
                                                (jira-api::get-projects *auth*))))
83 99
       ((getopt :long-name "post-issue") (yason:encode (jira-api::read-issue)))
84
-      (t   (do-cmdline-options (option name value source)
85
-                               (print (list option name value source)))
86
-           (terpri)
87
-           (exit)))))
100
+      (t  (help) (exit)))))
88 101
 
89 102
 (dump "jira-client" main)