forked from Silex/docker.el
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-volumes.el
94 lines (76 loc) · 3.02 KB
/
docker-volumes.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
;;; docker-volumes.el --- Emacs interface to docker-volume
;; Author: Philippe Vaucher <[email protected]>
;; This file is NOT part of GNU Emacs.
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;;; Code:
(require 'docker-process)
(require 'docker-utils)
(require 'magit-popup)
(require 'tablist)
(defun docker-volumes-entries ()
"Returns the docker volumes data for `tabulated-list-entries'."
(let* ((data (docker "volume" "ls"))
(lines (cdr (s-split "\n" data t))))
(-map #'docker-volume-parse lines)))
(defun docker-volume-parse (line)
"Convert a LINE from \"docker volume ls\" to a `tabulated-list-entries' entry."
(let ((data (s-split " \\{3,15\\}" line t)))
(list (nth 1 data) (apply #'vector data))))
(defun docker-read-volume-name (prompt)
"Read a volume name using PROMPT."
(completing-read prompt (-map #'car (docker-volumes-entries))))
;;;###autoload
(defun docker-volume-rm (name)
"Destroy the volume named NAME."
(interactive (list (docker-read-volume-name "Delete volume: ")))
(docker "volume rm" name))
(defun docker-volumes-rm-selection ()
"Run `docker-volume-rm' on the volumes selection."
(interactive)
(--each (docker-utils-get-marked-items-ids)
(docker "volume rm" it))
(tablist-revert))
(docker-utils-define-popup docker-volumes-rm-popup
"Popup for removing volumes."
'docker-volumes-popups
:man-page "docker-volume-rm"
:actions '((?D "Remove" docker-volumes-rm-selection)))
(defun docker-volumes-refresh ()
"Refresh the volumes list."
(setq tabulated-list-entries (docker-volumes-entries)))
(defvar docker-volumes-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "D" 'docker-volumes-rm-popup)
map)
"Keymap for `docker-volumes-mode'.")
;;;###autoload
(defun docker-volumes ()
"List docker volumes."
(interactive)
(docker-utils-pop-to-buffer "*docker-volumes*")
(docker-volumes-mode)
(tablist-revert))
(define-derived-mode docker-volumes-mode tabulated-list-mode "Volumes Menu"
"Major mode for handling a list of docker volumes."
(setq tabulated-list-format [("Driver" 10 t)("Name" 10 t)])
(setq tabulated-list-padding 2)
(setq tabulated-list-sort-key (cons "Driver" nil))
(add-hook 'tabulated-list-revert-hook 'docker-volumes-refresh nil t)
(tabulated-list-init-header)
(tablist-minor-mode))
(provide 'docker-volumes)
;;; docker-volumes.el ends here