git.fiddlerwoaroof.com
Browse code

Add info command-line argument, add primitives to cleanup watching

Ed Langley authored on 14/04/2018 16:56:50
Showing 2 changed files
... ...
@@ -1,5 +1,5 @@
1 1
 (defpackage :cloud-watcher.cli
2
-  (:import-from :cloud-watcher.main :stack-parameters :stack-outputs :stack-for-name)
2
+  (:import-from :cloud-watcher.main :stack-parameters :stack-outputs :stack-for-name :stack-info)
3 3
   (:import-from :cloud-watcher.aws-result :start-date-time :end-date-time)
4 4
   (:import-from :serapeum :op)
5 5
   (:import-from :clon :defsynopsis :group :flag :stropt)
... ...
@@ -16,6 +16,8 @@
16 16
            (flag :short-name "p" :long-name "parameters" :description "show stack parameters")
17 17
            (flag :short-name "o" :long-name "outputs" :description "show stack outputs")
18 18
            (flag :short-name "w" :long-name "watch" :description "watch a cloudformation stack until it's done processing")
19
+           (flag :short-name "i" :long-name "info" :description "get parameters, status and output of a stack")
20
+           #+null
19 21
            (flag :short-name "s" :long-name "start")
20 22
            (stropt :long-name "aws-region" :default-value "us-west-2")
21 23
            (flag :short-name "u" :long-name "update"))
... ...
@@ -30,6 +32,9 @@
30 32
 (defun stack-outputs-main (name)
31 33
   (stack-outputs (stack-for-name name)))
32 34
 
35
+(defun stack-info-main (name)
36
+  (stack-info (stack-for-name name)))
37
+
33 38
 (defun run-tests ()
34 39
   (st:test :package (find-package :cloud-watcher.aws-result))
35 40
   (st:test :package (find-package :cloud-watcher.main))
... ...
@@ -56,6 +61,7 @@
56 61
     (format *error-output* "~&IN REGION: ~a~%" region)
57 62
 
58 63
     (cond ((clon:getopt :long-name "help") (clon:help))
64
+          ((clon:getopt :long-name "info") (stack-info-main (car files)))
59 65
           ((clon:getopt :long-name "watch") (cloud-watcher.main:watch-stack (car files)))
60 66
           ((clon:getopt :long-name "outputs") (stack-outputs-main (car files)))
61 67
           ((clon:getopt :long-name "parameters") (stack-parameters-main (car files)))
... ...
@@ -9,7 +9,8 @@
9 9
            #:stack-parameters
10 10
            #:stack-outputs
11 11
            #:stack-for-name
12
-           #:watch-stack))
12
+           #:watch-stack
13
+           #:stack-info))
13 14
 
14 15
 (in-package :cloud-watcher.main)
15 16
 
... ...
@@ -121,6 +122,9 @@
121 122
     (setf (stack stack-formatter) (refresh-stack (stack stack-formatter)))
122 123
     stack-formatter))
123 124
 
125
+(defmethod old-status ((stack cloud-watcher.aws-result:stack))
126
+  nil)
127
+
124 128
 (defun stack-info (the-stack)
125 129
   (with-accessors ((old-status old-status)) the-stack
126 130
     (let* ((current-status (stack-status the-stack)))
... ...
@@ -134,12 +138,15 @@
134 138
           (output-block the-stack)
135 139
           t))))
136 140
 
141
+(defun refreshing (refresh-function cb)
142
+  (lambda (thing)
143
+    (let ((refreshed-thing (funcall refresh-function thing)))
144
+      (values (funcall cb refreshed-thing)
145
+              refreshed-thing))))
146
+
137 147
 (defun watch-stack (name)
138 148
   (format t "~&Watching ~s~2%" name)
139
-  (every-five-seconds (lambda (stale-stack)
140
-                        (let ((the-stack (refresh-stack stale-stack)))
141
-                          (values (stack-info the-stack)
142
-                                  the-stack)))
149
+  (every-five-seconds (refreshing 'refresh-stack 'stack-info)
143 150
                       (list name))
144 151
   (fresh-line))
145 152