-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathec2-cli.el
47 lines (34 loc) · 1.19 KB
/
ec2-cli.el
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
;;; ec2-ecli.el -*- lexical-binding: t; -*-
;; Copyright (C) 2022 Samuel Thomas
;;; Code:
(require 'deferred)
(require 'dash)
(require 'json)
(require 'ec2-render)
(cl-defun ec2/run-cmd-async (cmd &key (json t))
"Run ec2 `cmd', and parse the resulting json."
(let ((c cmd))
(deferred:$
(deferred:next
(lambda () (setq ec2/last-error-message nil)))
(deferred:nextc it
`(lambda (_)
(deferred:process "aws" ,@c "--no-cli-pager")))
(deferred:nextc it
(lambda (raw-string)
(if json
(if (not (string-empty-p raw-string))
(ec2/arrays-to-lists (json-read-from-string raw-string))
"")
raw-string))))))
(cl-defun ec2/query-cmd (&key cmd query)
`(ec2/run-cmd-async '("ec2" ,@cmd "--query" ,query)))
(defun ec2/arrays-to-lists (elem)
"Convert lisp vectors into lists so that they are easier to process later."
(if (vectorp elem)
(-map 'ec2/arrays-to-lists elem)
(if (or (equal elem nil) (equal elem ""))
"<none>"
elem)))
(provide 'ec2-cli)
;;; ec2-cli.el ends here