guix: home: Add list-generations.

Julien LepillerThu Sep 19 22:50:49+0200 2019

0936fbc

guix: home: Add list-generations. * guix/scripts/home.scm: Support list-generations command.

guix/scripts/home.scm

5858
   reconfigure      switch to or create a new home configuration\n"))
5959
  (display (G_ "\
6060
   build            build the home configuration without installing anything\n"))
61+
  (display (G_ "\
62+
   list-generations list the home generations\n"))
6163
  (show-build-options-help)
6264
  (display (G_ "
6365
  -h, --help             display this help and exit"))

179181
              (rename-file %home data-directory)))
180182
          (symlink %current-home %home)))))
181183
184+
(define (list-generations pattern)
185+
  "Display in a human-readable format all the home generations matching
186+
PATTERN, a string.  When PATTERN is #f, display all the home generations."
187+
  (cond ((not (file-exists? %current-home))             ; XXX: race condition
188+
	 (raise (condition (&profile-not-found-error
189+
			     (profile %current-home)))))
190+
	((not pattern)
191+
	 (for-each (lambda (number) (display-generation %current-home number)) (profile-generations %current-home)))
192+
	((matching-generations pattern %current-home)
193+
	 =>
194+
	 (lambda (numbers)
195+
	   (if (null-list? numbers)
196+
	       (exit 1)
197+
	       (leave-on-EPIPE
198+
		 (for-each (lambda (number) (display-generation %current-home number)) numbers)))))))
199+
200+
182201
;;;
183202
;;; Entry point.
184203
;;;

280299
  (case command
281300
    ;; The following commands do not need to use the store, and they do not need
282301
    ;; an operating system configuration file.
302+
    ((list-generations)
303+
     (let ((pattern (match args
304+
			   (() #f)
305+
			   ((pattern) pattern)
306+
			   (x (leave (G_ "wrong number of arguments~%"))))))
307+
       (list-generations pattern)))
283308
    ;; The following commands need to use the store, but they do not need an
284309
    ;; operating system configuration file.
285310
    ;; The following commands need to use the store, and they also

293318
        (alist-cons 'argument arg result)
294319
        (let ((action (string->symbol arg)))
295320
          (case action
296-
            ((build reconfigure)
321+
            ((build reconfigure list-generations)
297322
             (alist-cons 'action action result))
298323
            (else (leave (G_ "~a: unknown action~%") action))))))
299324