graph: Add '--expression'.

* guix/scripts/graph.scm (%options, show-help): Add '--expression'.
  (guix-graph): Call 'read/eval-package-expression' for 'expression'
  pairs in OPTS.
* tests/guix-graph.sh: Add tests.
* doc/guix.texi (Invoking guix graph): Document it.
This commit is contained in:
Ludovic Courtès 2015-09-02 15:23:52 +02:00
parent 4650a77ea8
commit 4c8f997a7d
3 changed files with 27 additions and 5 deletions

View File

@ -4417,6 +4417,16 @@ the values listed above.
@item --list-types @item --list-types
List the supported graph types. List the supported graph types.
@item --expression=@var{expr}
@itemx -e @var{expr}
Consider the package @var{expr} evaluates to.
This is useful to precisely refer to a package, as in this example:
@example
guix graph -e '(@@@@ (gnu packages commencement) gnu-make-final)'
@end example
@end table @end table

View File

@ -380,6 +380,9 @@ given BACKEND. Use NODE-TYPE to traverse the DAG."
(lambda (opt name arg result) (lambda (opt name arg result)
(list-node-types) (list-node-types)
(exit 0))) (exit 0)))
(option '(#\e "expression") #t #f
(lambda (opt name arg result)
(alist-cons 'expression arg result)))
(option '(#\h "help") #f #f (option '(#\h "help") #f #f
(lambda args (lambda args
(show-help) (show-help)
@ -397,6 +400,8 @@ Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
-t, --type=TYPE represent nodes of the given TYPE")) -t, --type=TYPE represent nodes of the given TYPE"))
(display (_ " (display (_ "
--list-types list the available graph types")) --list-types list the available graph types"))
(display (_ "
-e, --expression=EXPR consider the package EXPR evaluates to"))
(newline) (newline)
(display (_ " (display (_ "
-h, --help display this help and exit")) -h, --help display this help and exit"))
@ -417,12 +422,14 @@ Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
(with-error-handling (with-error-handling
(let* ((opts (parse-command-line args %options (let* ((opts (parse-command-line args %options
(list %default-options))) (list %default-options)))
(specs (filter-map (match-lambda
(('argument . spec) spec)
(_ #f))
opts))
(type (assoc-ref opts 'node-type)) (type (assoc-ref opts 'node-type))
(packages (map specification->package specs))) (packages (filter-map (match-lambda
(('argument . spec)
(specification->package spec))
(('expression . exp)
(read/eval-package-expression exp))
(_ #f))
opts)))
(with-store store (with-store store
(run-with-store store (run-with-store store
(mlet %store-monad ((nodes (mapm %store-monad (mlet %store-monad ((nodes (mapm %store-monad

View File

@ -32,3 +32,8 @@ done
guix build guile-bootstrap guix build guile-bootstrap
guix graph -t references guile-bootstrap | grep guile-bootstrap guix graph -t references guile-bootstrap | grep guile-bootstrap
guix graph -e '(@ (gnu packages bootstrap) %bootstrap-guile)' \
| grep guile-bootstrap
if guix graph -e +; then false; else true; fi