2011-05-30 23:02:03 +02:00
|
|
|
|
;;; List --- List scripts that can be invoked by guild -*- coding: iso-8859-1 -*-
|
2011-05-08 22:51:07 +01:00
|
|
|
|
|
|
|
|
|
|
;;;; Copyright (C) 2009, 2010, 2011 Free Software Foundation, Inc.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This library is free software; you can redistribute it and/or
|
|
|
|
|
|
;;;; modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License as published by the Free Software Foundation; either
|
|
|
|
|
|
;;;; version 3 of the License, or (at your option) any later version.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; This library is distributed in the hope that it will be useful,
|
|
|
|
|
|
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
|
;;;; Lesser General Public License for more details.
|
|
|
|
|
|
;;;;
|
|
|
|
|
|
;;;; You should have received a copy of the GNU Lesser General Public
|
|
|
|
|
|
;;;; License along with this library; if not, write to the Free
|
|
|
|
|
|
;;;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
|
|
;;;; Boston, MA 02110-1301 USA
|
|
|
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
|
|
;; Usage: list
|
|
|
|
|
|
;;
|
2011-05-30 23:02:03 +02:00
|
|
|
|
;; List scripts that can be invoked by guild.
|
2011-05-08 22:51:07 +01:00
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (scripts list)
|
2011-07-23 13:52:51 +02:00
|
|
|
|
#:use-module (ice-9 format)
|
2011-05-08 22:51:07 +01:00
|
|
|
|
#:use-module ((srfi srfi-1) #:select (fold append-map))
|
|
|
|
|
|
#:export (list-scripts))
|
|
|
|
|
|
|
2011-07-23 17:50:37 +02:00
|
|
|
|
(define %include-in-guild-list #f)
|
|
|
|
|
|
(define %summary "List available guild commands.")
|
|
|
|
|
|
|
2011-05-08 22:51:07 +01:00
|
|
|
|
|
|
|
|
|
|
(define (directory-files dir)
|
|
|
|
|
|
(if (and (file-exists? dir) (file-is-directory? dir))
|
|
|
|
|
|
(let ((dir-stream (opendir dir)))
|
|
|
|
|
|
(let loop ((new (readdir dir-stream))
|
|
|
|
|
|
(acc '()))
|
|
|
|
|
|
(if (eof-object? new)
|
|
|
|
|
|
(begin
|
|
|
|
|
|
(closedir dir-stream)
|
|
|
|
|
|
acc)
|
|
|
|
|
|
(loop (readdir dir-stream)
|
|
|
|
|
|
(if (or (string=? "." new) ; ignore
|
|
|
|
|
|
(string=? ".." new)) ; ignore
|
|
|
|
|
|
acc
|
|
|
|
|
|
(cons new acc))))))
|
|
|
|
|
|
'()))
|
|
|
|
|
|
|
|
|
|
|
|
(define (strip-extensions path)
|
|
|
|
|
|
(or-map (lambda (ext)
|
|
|
|
|
|
(and
|
|
|
|
|
|
(string-suffix? ext path)
|
2011-07-23 13:52:51 +02:00
|
|
|
|
;; We really can't be adding e.g. ChangeLog-2008 to the set
|
|
|
|
|
|
;; of runnable scripts, just because "" is a valid
|
|
|
|
|
|
;; extension, by default. So hack around that here.
|
|
|
|
|
|
(not (string-null? ext))
|
2011-05-08 22:51:07 +01:00
|
|
|
|
(substring path 0
|
|
|
|
|
|
(- (string-length path) (string-length ext)))))
|
|
|
|
|
|
(append %load-compiled-extensions %load-extensions)))
|
|
|
|
|
|
|
|
|
|
|
|
(define (unique l)
|
|
|
|
|
|
(cond ((null? l) l)
|
|
|
|
|
|
((null? (cdr l)) l)
|
|
|
|
|
|
((equal? (car l) (cadr l)) (unique (cdr l)))
|
|
|
|
|
|
(else (cons (car l) (unique (cdr l))))))
|
|
|
|
|
|
|
|
|
|
|
|
(define (find-submodules head)
|
|
|
|
|
|
(let ((shead (map symbol->string head)))
|
|
|
|
|
|
(unique
|
|
|
|
|
|
(sort
|
|
|
|
|
|
(append-map (lambda (path)
|
|
|
|
|
|
(fold (lambda (x rest)
|
|
|
|
|
|
(let ((stripped (strip-extensions x)))
|
|
|
|
|
|
(if stripped (cons stripped rest) rest)))
|
|
|
|
|
|
'()
|
|
|
|
|
|
(directory-files
|
|
|
|
|
|
(fold (lambda (x y) (in-vicinity y x)) path shead))))
|
|
|
|
|
|
%load-path)
|
|
|
|
|
|
string<?))))
|
|
|
|
|
|
|
2011-07-23 13:52:51 +02:00
|
|
|
|
(define (main . args)
|
|
|
|
|
|
(display "\
|
|
|
|
|
|
Usage: guild COMMAND [ARGS]
|
2011-05-08 22:51:07 +01:00
|
|
|
|
|
2011-07-23 13:52:51 +02:00
|
|
|
|
guild runs command-line scripts provided by GNU Guile and related
|
|
|
|
|
|
programs. See \"Using Guile Tools\" in the Guile manual, for more
|
|
|
|
|
|
information.
|
|
|
|
|
|
|
|
|
|
|
|
Commands:
|
|
|
|
|
|
")
|
|
|
|
|
|
|
2011-07-23 17:50:37 +02:00
|
|
|
|
(let ((all? (or (equal? args '("--all"))
|
|
|
|
|
|
(equal? args '("-a")))))
|
|
|
|
|
|
(for-each
|
|
|
|
|
|
(lambda (name)
|
|
|
|
|
|
(let* ((modname `(scripts ,(string->symbol name)))
|
|
|
|
|
|
(mod (resolve-module modname #:ensure #f))
|
|
|
|
|
|
(summary (and mod (and=> (module-variable mod '%summary)
|
|
|
|
|
|
variable-ref))))
|
|
|
|
|
|
(if (and mod
|
|
|
|
|
|
(or all?
|
|
|
|
|
|
(let ((v (module-variable mod '%include-in-guild-list)))
|
|
|
|
|
|
(if v (variable-ref v) #t))))
|
|
|
|
|
|
(if summary
|
|
|
|
|
|
(format #t " ~A ~23t~a\n" name summary)
|
|
|
|
|
|
(format #t " ~A\n" name)))))
|
|
|
|
|
|
(find-submodules '(scripts))))
|
2011-07-23 13:52:51 +02:00
|
|
|
|
|
|
|
|
|
|
(display "\
|
|
|
|
|
|
|
|
|
|
|
|
If COMMAND is \"list\" or omitted, display available scripts, otherwise
|
|
|
|
|
|
COMMAND is run with ARGS.
|
|
|
|
|
|
"))
|