Specify usage information in the command
This commit is contained in:
parent
b1a2359036
commit
39b5431da1
1 changed files with 88 additions and 39 deletions
127
gitto/main.scm
127
gitto/main.scm
|
@ -31,16 +31,22 @@
|
||||||
(define-syntax define-command
|
(define-syntax define-command
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((_ (name . args)
|
((_ (name . args)
|
||||||
|
usage
|
||||||
|
longdoc
|
||||||
exp exp* ...)
|
exp exp* ...)
|
||||||
(begin
|
(begin
|
||||||
(set! command-list
|
(set! command-list
|
||||||
(cons
|
(cons
|
||||||
(cons (symbol->string (quote name))
|
(list (symbol->string (quote name))
|
||||||
(case-lambda
|
(cons
|
||||||
|
#:function
|
||||||
|
(case-lambda*
|
||||||
(args
|
(args
|
||||||
exp exp* ...)
|
exp exp* ...)
|
||||||
(lst (format #t "Wrong number of arguments.~%"))))
|
(lst (format #t "Wrong number of arguments.~%"))))
|
||||||
command-list))))))
|
(cons #:usage usage)
|
||||||
|
(cons #:documentation longdoc))
|
||||||
|
command-list))))))
|
||||||
|
|
||||||
(define command-list '())
|
(define command-list '())
|
||||||
(define config-exclusion-list '())
|
(define config-exclusion-list '())
|
||||||
|
@ -62,6 +68,9 @@ set in the current environment."
|
||||||
|
|
||||||
(define-command (version)
|
(define-command (version)
|
||||||
"Display version information."
|
"Display version information."
|
||||||
|
"Usage: gitto version
|
||||||
|
|
||||||
|
Displays version and some copyright information."
|
||||||
(display "gitto 0.1.0") (newline)
|
(display "gitto 0.1.0") (newline)
|
||||||
(display "Copyright (C) 2012 Tom Willemse") (newline)
|
(display "Copyright (C) 2012 Tom Willemse") (newline)
|
||||||
(display "This program comes with ABSOLUTELY NO WARRANTY.") (newline)
|
(display "This program comes with ABSOLUTELY NO WARRANTY.") (newline)
|
||||||
|
@ -69,24 +78,25 @@ set in the current environment."
|
||||||
(display "under the terms of the GNU General Public License.") (newline)
|
(display "under the terms of the GNU General Public License.") (newline)
|
||||||
(display "For more information about these matters, see the file named COPYING.") (newline))
|
(display "For more information about these matters, see the file named COPYING.") (newline))
|
||||||
|
|
||||||
(define-command (help)
|
(define-command (help #:optional command)
|
||||||
"Display some help."
|
"Display this help."
|
||||||
(display "\
|
"Usage: gitto help [COMMAND]
|
||||||
gitto [command [arguments ...]]
|
|
||||||
add Register a new repository directory
|
Display a help message. If COMMAND is not specified, print some
|
||||||
remove Remove a repository directory
|
information about gitto, otherwise print some information about
|
||||||
check Check if a repository has been registered
|
COMMAND."
|
||||||
list List all repositories and their status
|
(if command
|
||||||
list locations List all registered repositories' locations
|
(let ((command-spec (assoc-ref command-list command)))
|
||||||
purge Remove all repositories that don't exist
|
(if command-spec
|
||||||
config Show each repository's configuration
|
(format #t "~a~%" (assq-ref command-spec #:documentation))
|
||||||
config global Show template configuration
|
(format #t "Unknown command: ~a~%" command)))
|
||||||
config update Merge template configuration with each
|
(begin
|
||||||
repository's configuration
|
(display "gitto [command [arguments ...]]")
|
||||||
config hooks Install configured hooks for repositories
|
(newline)
|
||||||
version Display version
|
(for-each
|
||||||
help Display this help
|
(lambda (cmd)
|
||||||
"))
|
(format #t " ~a~20t~a~%" (car cmd) (assq-ref cmd #:usage)))
|
||||||
|
command-list))))
|
||||||
|
|
||||||
(define (known? repo)
|
(define (known? repo)
|
||||||
"Do we know REPO?"
|
"Do we know REPO?"
|
||||||
|
@ -112,12 +122,21 @@ gitto [command [arguments ...]]
|
||||||
(close-port port)))
|
(close-port port)))
|
||||||
|
|
||||||
(define-command (check repository)
|
(define-command (check repository)
|
||||||
"Check to see if REPOSITORY has been registered."
|
"Check to see if a repository has been registered."
|
||||||
|
"Usage: gitto check REPO
|
||||||
|
|
||||||
|
Checks whether or not the git repository REPO has been registered with
|
||||||
|
gitto."
|
||||||
(format #t "Repository is~a registered~%"
|
(format #t "Repository is~a registered~%"
|
||||||
(if (known? repository) "" " not")))
|
(if (known? repository) "" " not")))
|
||||||
|
|
||||||
(define-command (add repository)
|
(define-command (add repository)
|
||||||
"Register REPOSITORY in the repository list."
|
"Register a repository."
|
||||||
|
"Usage: gitto add REPO
|
||||||
|
|
||||||
|
Add REPO to the registered repository list. This command will fail if
|
||||||
|
REPO does not indicate a git repository or if it has already been
|
||||||
|
registered."
|
||||||
(set! repository (make <repository> (realpath repository)))
|
(set! repository (make <repository> (realpath repository)))
|
||||||
(if (not (known? repository))
|
(if (not (known? repository))
|
||||||
(begin
|
(begin
|
||||||
|
@ -138,7 +157,12 @@ gitto [command [arguments ...]]
|
||||||
(newline))
|
(newline))
|
||||||
|
|
||||||
(define-command (remove repository)
|
(define-command (remove repository)
|
||||||
"Remove/unregister REPOSITORY from the repository list."
|
"Unregister a repository."
|
||||||
|
"Usage: gitto remove REPO
|
||||||
|
|
||||||
|
Removes REPO from the registered repository list. This command will
|
||||||
|
fail if REPO does not indicate a git repository of if it hasn't been
|
||||||
|
registered."
|
||||||
(unless (member repository repositories same-repository?)
|
(unless (member repository repositories same-repository?)
|
||||||
(set! repository (realpath repository)))
|
(set! repository (realpath repository)))
|
||||||
|
|
||||||
|
@ -153,6 +177,16 @@ gitto [command [arguments ...]]
|
||||||
|
|
||||||
(define-command (list . args)
|
(define-command (list . args)
|
||||||
"List information about every repository."
|
"List information about every repository."
|
||||||
|
"Usage: gitto list
|
||||||
|
gitto list locations
|
||||||
|
|
||||||
|
The first form shows an overview of the status of your registered
|
||||||
|
repositories and their branches. By default branches without changer
|
||||||
|
aren't shown, but you can change this behaviour by setting the
|
||||||
|
`show-unchanged-branches?' variable in your init file.
|
||||||
|
|
||||||
|
The second form prints the location on your filesystem for each
|
||||||
|
registered repository as absolute paths."
|
||||||
(if (and (not (eq? args '())) (equal? (car args) "locations"))
|
(if (and (not (eq? args '())) (equal? (car args) "locations"))
|
||||||
(list-repository-locations)
|
(list-repository-locations)
|
||||||
(for-each print repositories)))
|
(for-each print repositories)))
|
||||||
|
@ -168,7 +202,11 @@ gitto [command [arguments ...]]
|
||||||
(string<? (repo-location s1) (repo-location s2))))))
|
(string<? (repo-location s1) (repo-location s2))))))
|
||||||
|
|
||||||
(define-command (purge)
|
(define-command (purge)
|
||||||
"Purge all items from the list that can no longer be found."
|
"Purge all registered repositories that can no longer be found."
|
||||||
|
"Usage: gitto purge
|
||||||
|
|
||||||
|
Go through the list of registered repositories and remove all the ones
|
||||||
|
which no longer point to a git repository."
|
||||||
(set! repositories
|
(set! repositories
|
||||||
(filter (lambda (repo)
|
(filter (lambda (repo)
|
||||||
(file-exists? (repo-location repo)))
|
(file-exists? (repo-location repo)))
|
||||||
|
@ -179,18 +217,28 @@ gitto [command [arguments ...]]
|
||||||
"Show the template specified in `global-config'."
|
"Show the template specified in `global-config'."
|
||||||
(write-config global-config))
|
(write-config global-config))
|
||||||
|
|
||||||
(define-command (config . args)
|
(define-command (config #:optional sub)
|
||||||
"Do something with the config module.
|
"Manage your repositories' configurations."
|
||||||
|
"Usage: gitto config
|
||||||
|
gitto config global
|
||||||
|
gitto config update
|
||||||
|
gitto config hooks
|
||||||
|
|
||||||
If ARGS is an empty list, show each repository's current
|
The first form prints the configurations for each registered
|
||||||
configuration. If the car of ARGS is `global' show the template
|
repository.
|
||||||
specified in the user's init file. If the car of ARGS is `update'
|
|
||||||
merge the specified template and each repository's configuration,
|
The second form shows what your configured configuration template
|
||||||
excluding the repositories in `config-exclusion-list'. If the car of
|
looks like as a git configuration file. This does not expand the `%a'
|
||||||
ARGS is `hooks' install configured hooks in each repository, excluding
|
format specifier which can be used to indicate the repository name.
|
||||||
repositories in `config-exclusion-list'."
|
|
||||||
|
The third form merges the template in and existing configurations,
|
||||||
|
overwriting settings when necessary. The repositories in the
|
||||||
|
`config-exclusion-list' will be skipped. *Note:* This is a destructive
|
||||||
|
operation, you should be mindful.
|
||||||
|
|
||||||
|
The fourth form installs the configured hooks into each repository."
|
||||||
(cond
|
(cond
|
||||||
((eq? args '())
|
((not sub)
|
||||||
(for-each (lambda (repo)
|
(for-each (lambda (repo)
|
||||||
(display (string-upcase (repo-name repo)))
|
(display (string-upcase (repo-name repo)))
|
||||||
(newline)
|
(newline)
|
||||||
|
@ -198,9 +246,9 @@ repositories in `config-exclusion-list'."
|
||||||
(newline)
|
(newline)
|
||||||
(newline))
|
(newline))
|
||||||
repositories))
|
repositories))
|
||||||
((equal? (car args) "global") (show-global-config))
|
((equal? sub "global") (show-global-config))
|
||||||
((equal? (car args) "update") (update-config))
|
((equal? sub "update") (update-config))
|
||||||
((equal? (car args) "hooks")
|
((equal? sub "hooks")
|
||||||
(for-each (lambda (r)
|
(for-each (lambda (r)
|
||||||
(unless (member (repo-name r) config-exclusion-list)
|
(unless (member (repo-name r) config-exclusion-list)
|
||||||
(install-hooks (repo-location r))))
|
(install-hooks (repo-location r))))
|
||||||
|
@ -236,7 +284,8 @@ Don't do anything if REPO has been added to `config-exclusion-list'."
|
||||||
(assoc-ref command-list
|
(assoc-ref command-list
|
||||||
(car (if command? command-spec '("list"))))))
|
(car (if command? command-spec '("list"))))))
|
||||||
(if command
|
(if command
|
||||||
(apply command (if command? (cdr command-spec) '()))
|
(apply (assq-ref command #:function)
|
||||||
|
(if command? (cdr command-spec) '()))
|
||||||
(format #t "Unknown command: ~a~%" (car command-spec))))))
|
(format #t "Unknown command: ~a~%" (car command-spec))))))
|
||||||
|
|
||||||
(define repositories-file (data-file "repos.scm"))
|
(define repositories-file (data-file "repos.scm"))
|
||||||
|
|
Loading…
Reference in a new issue