From a45509d28eb14cc89548c29076c018044278035c Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 5 Jul 2020 17:43:39 -0500 Subject: [PATCH] Add list-pkgs and list-installed to jpm. --- CHANGELOG.md | 1 + jpm | 19 +++++++++++++++++++ jpm.1 | 9 +++++++++ src/boot/boot.janet | 2 +- test/suite7.janet | 5 +++++ 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16307c21..5433d8fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All notable changes to this project will be documented in this file. ## Unreleased - ??? +- Add `jpm list-installed` subcommand to see which packages are installed. - Add `math/int-min`, `math/int-max`, `math/int32-min`, and `math/int32-max` for getting integer limits. - The gc interval is now autotuned, to prevent very bad gc behavior. - Improvements to the bytecode compiler, Janet will now generate more efficient bytecode. diff --git a/jpm b/jpm index e7f42f40..f19a9e18 100755 --- a/jpm +++ b/jpm @@ -1106,6 +1106,9 @@ Unprivileged project subcommands: run rule : run a rule. Can also run custom rules added via (phony "task" [deps...] ...) or (rule "ouput.file" [deps...] ...). rules : list rules available with run. + list-installed : list installed packages in the current syspath. + list-pkgs (search) : list packages in the package listing that the contain the string search. + If no search pattern is given, prints the entire package listing. rule-tree (root rule) (depth) : Print a nice tree to see what rules depend on other rules. Optionally provide a root rule to start printing from, and a max depth to print. Without these options, all rules will print @@ -1186,6 +1189,20 @@ Flags are: (def ks (sort (seq [k :keys (dyn :rules)] k))) (each k ks (print k))) +(defn list-installed + [] + (each x (os/dir (find-manifest-dir)) + (if (string/has-suffix? ".jdn" x) + (print (string/slice x 0 -5))))) + +(defn list-pkgs + [&opt search] + (def pkgs-mod (require "pkgs")) + (eachk p (get-in pkgs-mod ['packages :value] []) + (if search + (if (string/find search p) (print p)) + (print p)))) + (defn update-pkgs [] (install-git (dyn :pkglist default-pkglist))) @@ -1227,6 +1244,8 @@ Flags are: "debug-repl" jpm-debug-repl "rule-tree" show-rule-tree "show-paths" show-paths + "list-installed" list-installed + "list-pkgs" list-pkgs "clear-cache" clear-cache "clear-manifest" clear-manifest "run" local-rule diff --git a/jpm.1 b/jpm.1 index d3c9210d..a20bd168 100644 --- a/jpm.1 +++ b/jpm.1 @@ -139,6 +139,15 @@ date or too large, clear-cache will remove the cache and jpm will rebuild it when needed. clear-cache is a global command, so a project.janet is not required. +.TP +.BR list-installed +List all installed packages in the current syspath. + +.TP +.BR list-pkgs [\fBsearch\fR] +List all package aliases in the current package listing that contain the given search string. +If no search string is given, prints the entire listing. + .TP .BR clear-manifest jpm creates a manifest directory that contains a list of all installed files. diff --git a/src/boot/boot.janet b/src/boot/boot.janet index c90fae8d..bb3f5138 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -497,7 +497,7 @@ (defmacro eachk "Loop over each key in ds. Returns nil." [x ds & body] - (each-template x ds :each body)) + (each-template x ds :keys body)) (defmacro eachp "Loop over each (key, value) pair in ds. Returns nil." diff --git a/test/suite7.janet b/test/suite7.janet index 0fa5bf00..edf16598 100644 --- a/test/suite7.janet +++ b/test/suite7.janet @@ -315,4 +315,9 @@ (assert (= 40 counter) "if-with 1") +(def a @[]) +(eachk x [:a :b :c :d] + (array/push a x)) +(assert (deep= (range 4) a) "eachk 1") + (end-suite)