branch: externals/system-packages
commit cc1d463762e619c25a28182e0a3467a08568b725
Merge: 52b9bb0804 7476a11210
Author: Alex Branham <[email protected]>
Commit: Alex Branham <[email protected]>
Merge branch 'package-list' into 'master'
Allow system-packages-ensure to take a list of packages
Closes #33
See merge request jabranham/system-packages!41
---
system-packages.el | 23 ++++++++++++++++-------
test/system-packages-test.el | 13 +++++++++++--
2 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/system-packages.el b/system-packages.el
index 3ec95650a9..99ee10fa3b 100644
--- a/system-packages.el
+++ b/system-packages.el
@@ -40,6 +40,9 @@
;;
;;; Code:
+(eval-when-compile
+ (require 'cl-lib))
+
(defgroup system-packages nil
"Manages system packages."
:tag "System Packages"
@@ -362,7 +365,10 @@ of passing additional arguments to the package manager."
(let ((command
(cdr (assoc action (cdr (assoc system-packages-package-manager
system-packages-supported-package-managers)))))
- (pack (when pack (shell-quote-argument pack)))
+ (pack (cond ((stringp pack)
+ (shell-quote-argument pack))
+ (pack
+ (mapconcat #'shell-quote-argument pack " "))))
(noconfirm (when system-packages-noconfirm
(cdr (assoc 'noconfirm
(cdr (assoc system-packages-package-manager
@@ -405,19 +411,22 @@ manger."
;;;###autoload
(defun system-packages-ensure (pack &optional args)
"Ensure PACK is installed on system.
-Search for PACK with `system-packages-package-installed-p', and
-install the package if not found. Use ARGS to pass options to
-the package manager."
+Search for PACK (or each element of PACK, if it is a list) with
+`system-packages-package-installed-p', and install the package(s) if not
+found. Use ARGS to pass options to the package manager."
(interactive "sPackage to ensure is present: ")
(if (system-packages-package-installed-p pack)
t
(system-packages-install pack args)))
;;;###autoload
-(defalias 'system-packages-package-installed-p #'executable-find
+(defun system-packages-package-installed-p (pack)
"Return t if PACK is installed.
-Currently an alias for `executable-find', so it will give wrong
-results if the package and executable names are different.")
+Currently relies on `executable-find', so it will give wrong
+results if the package and executable names are different."
+ (if (listp pack)
+ (cl-loop for p in pack always (executable-find p))
+ (executable-find pack)))
;;;###autoload
(defun system-packages-search (pack &optional args)
diff --git a/test/system-packages-test.el b/test/system-packages-test.el
index 0304474c98..0426958795 100644
--- a/test/system-packages-test.el
+++ b/test/system-packages-test.el
@@ -37,8 +37,9 @@
(should (string=
(let ((system-packages-use-sudo nil)
(system-packages-package-manager 'dnf))
- (system-packages-get-command 'install "pkgconfig(enchant-2)"))
- "dnf install pkgconfig\\(enchant-2\\)")))
+ (system-packages-get-command
+ 'install (list "enchant" "pkgconfig(enchant-2)")))
+ "dnf install enchant pkgconfig\\(enchant-2\\)")))
(ert-deftest system-packages-get-install-noconfirm ()
"Return correct installation command."
@@ -67,4 +68,12 @@
(let ((system-packages-package-manager 'pacaur))
(system-packages-get-command 'install))))
+(ert-deftest system-packages-package-installed-p ()
+ "Return correct package installation status."
+ (should (system-packages-package-installed-p "emacs"))
+ (should (system-packages-package-installed-p (list "bash" "emacs")))
+ (should (not (system-packages-package-installed-p "no-such-package")))
+ (should (not (system-packages-package-installed-p
+ (list "no-such-package" "no-such-package-2")))))
+
;;; system-packages-test.el ends here