civodul pushed a commit to branch wip-simplified-packages in repository guix.
commit 06ed214586d4977df94a4cf3ccb031d3e5384db7 Author: Ludovic Courtès <[email protected]> AuthorDate: Sun Jun 27 16:13:54 2021 +0200 squash! Add 'guix style'. Add the -e/--expression option. --- doc/guix.texi | 12 ++++++++++++ guix/scripts/style.scm | 23 ++++++++++++++++------- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index e1fd432..132c064 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12091,6 +12091,18 @@ appears in an inputs field. The available options are listed below. @itemx -L @var{directory} Add @var{directory} to the front of the package module search path (@pxref{Package Modules}). + +@item --expression=@var{expr} +@itemx -e @var{expr} +Style the package @var{expr} evaluates to. + +For example, running: + +@example +guix style -e '(@@ (gnu packages gcc) gcc-5)' +@end example + +styles the @code{gcc-5} package definition. @end table @node Invoking guix lint diff --git a/guix/scripts/style.scm b/guix/scripts/style.scm index c75b860..3e906ce 100644 --- a/guix/scripts/style.scm +++ b/guix/scripts/style.scm @@ -420,6 +420,10 @@ bailing out~%") (member "load-path" (option-names option))) %standard-build-options) + (option '(#\e "expression") #t #f + (lambda (opt name arg result) + (alist-cons 'expression arg result))) + (option '(#\h "help") #f #f (lambda args (show-help) @@ -433,6 +437,8 @@ bailing out~%") Update package definitions to the latest style.\n")) (display (G_ " -L, --load-path=DIR prepend DIR to the package module search path")) + (display (G_ " + -e, --expression=EXPR consider the package EXPR evaluates to")) (newline) (display (G_ " -h, --help display this help and exit")) @@ -459,17 +465,20 @@ Update package definitions to the latest style.\n")) (parse-command-line args %options (list %default-options) #:build-options? #f)) - (let* ((opts (parse-options)) - (specs (filter-map (match-lambda - (('argument . spec) spec) - (_ #f)) - opts))) + (let* ((opts (parse-options)) + (packages (filter-map (match-lambda + (('argument . spec) + (specification->package spec)) + (('expression . str) + (read/eval str)) + (_ #f)) + opts))) (for-each simplify-package-inputs ;; Sort package by source code location so that we start editing ;; files from the bottom and going upward. That way, the ;; 'location' field of <package> records is not invalidated as ;; we modify files. - (sort (if (null? specs) + (sort (if (null? packages) (fold-packages cons '() #:select? (const #t)) - (map specification->package specs)) + packages) (negate package-location<?)))))
