guix package: Exit with 1 when a generation cannot be listed.
[jackhill/guix/guix.git] / guix / scripts / package.scm
index c0cedcd..1f21890 100644 (file)
@@ -965,20 +965,28 @@ more information.~%"))
                         ((name version output location _)
                          (format #t "  ~a\t~a\t~a\t~a~%"
                                  name version output location)))
-                       (manifest-packages
-                        (profile-manifest
-                         (format #f "~a-~a-link" profile number))))
+
+                       ;; Show most recently installed packages last.
+                       (reverse
+                        (manifest-packages
+                         (profile-manifest
+                          (format #f "~a-~a-link" profile number)))))
              (newline)))
 
          (cond ((not (file-exists? profile)) ; XXX: race condition
                 (leave (_ "profile '~a' does not exist~%")
                        profile))
                ((string-null? pattern)
-                (for-each list-generation
-                          (generation-numbers profile)))
+                (let ((numbers (generation-numbers profile)))
+                  (if (equal? numbers '(0))
+                      (exit 1)
+                      (for-each list-generation numbers))))
                ((matching-generations pattern profile)
                 =>
-                (cut for-each list-generation <>))
+                (lambda (numbers)
+                  (if (null-list? numbers)
+                      (exit 1)
+                      (for-each list-generation numbers))))
                (else
                 (leave (_ "invalid syntax: ~a~%")
                        pattern)))
@@ -994,7 +1002,9 @@ more information.~%"))
                                  (regexp-exec regexp name))
                          (format #t "~a\t~a\t~a\t~a~%"
                                  name (or version "?") output path))))
-                     installed)
+
+                     ;; Show most recently installed packages last.
+                     (reverse installed))
            #t))
 
         (('list-available regexp)