guix: home: Add list-generations. * guix/scripts/home.scm: Support list-generations command.
guix/scripts/home.scm
| 58 | 58 | reconfigure switch to or create a new home configuration\n")) | |
| 59 | 59 | (display (G_ "\ | |
| 60 | 60 | build build the home configuration without installing anything\n")) | |
| 61 | + | (display (G_ "\ | |
| 62 | + | list-generations list the home generations\n")) | |
| 61 | 63 | (show-build-options-help) | |
| 62 | 64 | (display (G_ " | |
| 63 | 65 | -h, --help display this help and exit")) | |
… | |||
| 179 | 181 | (rename-file %home data-directory))) | |
| 180 | 182 | (symlink %current-home %home))))) | |
| 181 | 183 | ||
| 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 | + | ||
| 182 | 201 | ;;; | |
| 183 | 202 | ;;; Entry point. | |
| 184 | 203 | ;;; | |
… | |||
| 280 | 299 | (case command | |
| 281 | 300 | ;; The following commands do not need to use the store, and they do not need | |
| 282 | 301 | ;; 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))) | |
| 283 | 308 | ;; The following commands need to use the store, but they do not need an | |
| 284 | 309 | ;; operating system configuration file. | |
| 285 | 310 | ;; The following commands need to use the store, and they also | |
… | |||
| 293 | 318 | (alist-cons 'argument arg result) | |
| 294 | 319 | (let ((action (string->symbol arg))) | |
| 295 | 320 | (case action | |
| 296 | - | ((build reconfigure) | |
| 321 | + | ((build reconfigure list-generations) | |
| 297 | 322 | (alist-cons 'action action result)) | |
| 298 | 323 | (else (leave (G_ "~a: unknown action~%") action)))))) | |
| 299 | 324 | ||