-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvention-container.el
104 lines (74 loc) · 3.79 KB
/
convention-container.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
(defun convention-detect-all-containers ()
"Returns a boolean indicating whether there are all containers
with 'convention' in their name"
(> (length (shell-command-to-string convention-docker-command-detect-all-containers)) 0))
(defun convention-list-all-containers ()
"Lists all containers containing 'connvention' in their name"
(remove "" (split-string (replace-regexp-in-string "/" "" (shell-command-to-string convention-docker-command-list-all-containers)) "\n")))
(defun convention-prompt-for-all-container ()
"Returns a string representing the name of a user selected container"
(interactive)
(if (convention-detect-all-containers)
(ido-completing-read "Available containers: " (convention-list-all-containers))
(error "There are no containers! You can start a container with M-x convention-start-container")))
(defun convention-detect-running-containers ()
"Returns a boolean indicating whether there are any running containers
with 'convention' in their name"
(> (length (shell-command-to-string convention-docker-command-detect-running-containers)) 0))
(defun convention-list-running-containers ()
"Lists all containers containing 'connvention' in their name"
(remove "" (split-string (replace-regexp-in-string "/" "" (shell-command-to-string convention-docker-command-list-running-containers)) "\n")))
(defun convention-prompt-for-running-container ()
"Returns a string representing the name of a user selected container"
(interactive)
(if (convention-detect-running-containers)
(ido-completing-read "Available containers: " (convention-list-running-containers))
(error "There are no running containers! You can start a container with M-x convention-start-container")))
(defun convention-format-stop-and-remove-container-command ()
"Returns a string representing a docker cli command to stop
and remove a container"
(let ((container (convention-prompt-for-all-container)))
(s-format
convention-docker-command-stop-and-remove-container
'aget
`(("container" . ,container)))))
(defun convention-stop-and-remove-container ()
"Removes a user specified container"
(interactive)
(let ((cmd (convention-format-stop-and-remove-container-command)))
(shell-command cmd)))
(defun convention-format-stop-container-command ()
"Returns a string representing a docker cli command to stop a
running container"
(let ((container (convention-prompt-for-running-container)))
(s-format
convention-docker-command-stop-container
'aget
`(("container" . ,container)))))
(defun convention-stop-container ()
"Stops a running container"
(interactive)
(let ((cmd (convention-format-stop-container-command)))
(shell-command cmd)))
(defun convention-detect-stopped-containers ()
(> (length (shell-command-to-string convention-docker-command-detect-stopped-containers)) 0))
(defun convention-list-stopped-containers ()
(remove "" (split-string (replace-regexp-in-string "/" "" (shell-command-to-string convention-docker-command-list-stopped-containers)) "\n")))
(defun convention-prompt-for-stopped-container ()
(interactive)
(if (convention-detect-stopped-containers)
(ido-completing-read "Available containers: " (convention-list-stopped-containers))
(error "There are no stopped containers!") ))
(defun convention-format-start-a-stopped-container-command ()
"Returns a string representing a docker cli command to stop a
running container"
(let ((container (convention-prompt-for-stopped-container)))
(s-format
convention-docker-command-start-a-stopped-container
'aget
`(("container" . ,container)))))
(defun convention-start-a-stopped-container ()
(interactive)
(let ((cmd (convention-format-start-a-stopped-container-command)))
(shell-command cmd)))
(provide 'convention-container)