graph: Add "list-backend" and "backend" options.

* guix/graph.scm (%graph-backends): New variable.
* guix/scripts/graph.scm (lookup-backend, list-backends): New
procedures.
(%options): Add options for "backend" and "list-backends".
(show-help): Add help texts for "backend" and "list-backend" options.
(%default-options): Add "backend" default.
(guix-graph): Pass backend argument to "export-graph".
* doc/guix.texi (Invoking guix graph): Document the new options.
This commit is contained in:
Ricardo Wurmus 2016-10-21 23:59:00 +02:00
parent 51377437a1
commit 642339dc3f
No known key found for this signature in database
GPG Key ID: 197A5888235FACAC
3 changed files with 51 additions and 2 deletions

View File

@ -5827,6 +5827,13 @@ the values listed above.
@item --list-types @item --list-types
List the supported graph types. List the supported graph types.
@item --backend=@var{backend}
@itemx -b @var{backend}
Produce a graph using the selected @var{backend}.
@item --list-backends
List the supported graph backends.
@item --expression=@var{expr} @item --expression=@var{expr}
@itemx -e @var{expr} @itemx -e @var{expr}
Consider the package @var{expr} evaluates to. Consider the package @var{expr} evaluates to.

View File

@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org> ;;; Copyright © 2015, 2016 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -41,6 +42,7 @@
node-transitive-edges node-transitive-edges
node-reachable-count node-reachable-count
%graph-backends
%graphviz-backend %graphviz-backend
graph-backend? graph-backend?
graph-backend graph-backend
@ -179,6 +181,14 @@ typically returned by 'node-edges' or 'node-back-edges'."
emit-prologue emit-epilogue emit-prologue emit-epilogue
emit-node emit-edge)) emit-node emit-edge))
;;;
;;; Shared.
;;;
(define %graph-backends
(list %graphviz-backend))
(define* (export-graph sinks port (define* (export-graph sinks port
#:key #:key
reverse-edges? node-type reverse-edges? node-type

View File

@ -337,6 +337,13 @@ substitutes."
%node-types) %node-types)
(leave (_ "~a: unknown node type~%") name))) (leave (_ "~a: unknown node type~%") name)))
(define (lookup-backend name)
"Return the graph backend called NAME. Raise an error if it is not found."
(or (find (lambda (backend)
(string=? (graph-backend-name backend) name))
%graph-backends)
(leave (_ "~a: unknown backend~%") name)))
(define (list-node-types) (define (list-node-types)
"Print the available node types along with their synopsis." "Print the available node types along with their synopsis."
(display (_ "The available node types are:\n")) (display (_ "The available node types are:\n"))
@ -347,6 +354,16 @@ substitutes."
(node-type-description type))) (node-type-description type)))
%node-types)) %node-types))
(define (list-backends)
"Print the available backends along with their synopsis."
(display (_ "The available backend types are:\n"))
(newline)
(for-each (lambda (backend)
(format #t " - ~a: ~a~%"
(graph-backend-name backend)
(graph-backend-description backend)))
%graph-backends))
;;; ;;;
;;; Command-line options. ;;; Command-line options.
@ -361,6 +378,14 @@ substitutes."
(lambda (opt name arg result) (lambda (opt name arg result)
(list-node-types) (list-node-types)
(exit 0))) (exit 0)))
(option '(#\b "backend") #t #f
(lambda (opt name arg result)
(alist-cons 'backend (lookup-backend arg)
result)))
(option '("list-backends") #f #f
(lambda (opt name arg result)
(list-backends)
(exit 0)))
(option '(#\e "expression") #t #f (option '(#\e "expression") #t #f
(lambda (opt name arg result) (lambda (opt name arg result)
(alist-cons 'expression arg result))) (alist-cons 'expression arg result)))
@ -378,6 +403,10 @@ substitutes."
(display (_ "Usage: guix graph PACKAGE... (display (_ "Usage: guix graph PACKAGE...
Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n")) Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
(display (_ " (display (_ "
-b, --backend=TYPE produce a graph with the given backend TYPE"))
(display (_ "
--list-backends list the available graph backends"))
(display (_ "
-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"))
@ -392,7 +421,8 @@ Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
(show-bug-report-information)) (show-bug-report-information))
(define %default-options (define %default-options
`((node-type . ,%package-node-type))) `((node-type . ,%package-node-type)
(backend . ,%graphviz-backend)))
;;; ;;;
@ -407,6 +437,7 @@ Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
(lambda (arg result) (lambda (arg result)
(alist-cons 'argument arg result)) (alist-cons 'argument arg result))
%default-options)) %default-options))
(backend (assoc-ref opts 'backend))
(type (assoc-ref opts 'node-type)) (type (assoc-ref opts 'node-type))
(items (filter-map (match-lambda (items (filter-map (match-lambda
(('argument . (? store-path? item)) (('argument . (? store-path? item))
@ -429,7 +460,8 @@ Emit a Graphviz (dot) representation of the dependencies of PACKAGE...\n"))
items))) items)))
(export-graph (concatenate nodes) (export-graph (concatenate nodes)
(current-output-port) (current-output-port)
#:node-type type))))))) #:node-type type
#:backend backend)))))))
#t) #t)
;;; graph.scm ends here ;;; graph.scm ends here