1 ;;; List --- List scripts that can be invoked by guild -*- coding: iso-8859-1 -*-
3 ;;;; Copyright (C) 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free
17 ;;;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 ;;;; Boston, MA 02110-1301 USA
24 ;; List scripts that can be invoked by guild.
28 (define-module (scripts list)
29 #:use-module (srfi srfi-1)
30 #:export (list-scripts))
32 (define %include-in-guild-list #f)
33 (define %summary "An alias for \"help\".")
36 (define (directory-files dir)
37 (if (and (file-exists? dir) (file-is-directory? dir))
38 (let ((dir-stream (opendir dir)))
39 (let loop ((new (readdir dir-stream))
45 (loop (readdir dir-stream)
46 (if (or (string=? "." new) ; ignore
47 (string=? ".." new)) ; ignore
52 (define (strip-extensions path)
55 (string-suffix? ext path)
56 ;; We really can't be adding e.g. ChangeLog-2008 to the set
57 ;; of runnable scripts, just because "" is a valid
58 ;; extension, by default. So hack around that here.
59 (not (string-null? ext))
61 (- (string-length path) (string-length ext)))))
62 (append %load-compiled-extensions %load-extensions)))
67 ((equal? (car l) (cadr l)) (unique (cdr l)))
68 (else (cons (car l) (unique (cdr l))))))
70 (define (find-submodules head)
71 (let ((shead (map symbol->string head)))
74 (append-map (lambda (path)
75 (fold (lambda (x rest)
76 (let ((stripped (strip-extensions x)))
77 (if stripped (cons stripped rest) rest)))
80 (fold (lambda (x y) (in-vicinity y x)) path shead))))
84 (define (list-scripts . args)
86 ;; would be nice to show a summary.
88 (find-submodules '(scripts))))
91 (apply (@@ (scripts help) main) args))