64 lines
1.7 KiB
Racket
64 lines
1.7 KiB
Racket
#lang racket/base
|
|
|
|
(require racket/format
|
|
racket/system
|
|
"commands.rkt"
|
|
"racket-tools.rkt")
|
|
|
|
(provide coreutils-help
|
|
coreutils-help-search-term
|
|
raco-executable)
|
|
|
|
(define (arg->string arg)
|
|
(cond
|
|
[(string? arg) arg]
|
|
[(symbol? arg) (symbol->string arg)]
|
|
[else (~a arg)]))
|
|
|
|
(define (arg->symbol arg)
|
|
(cond
|
|
[(symbol? arg) arg]
|
|
[(string? arg) (string->symbol arg)]
|
|
[else #f]))
|
|
|
|
(define (coreutils-help-search-term value)
|
|
(define name (arg->symbol value))
|
|
(define command (and name (find-coreutils-command name)))
|
|
(if command
|
|
(symbol->string (coreutils-command-documentation-term command))
|
|
(arg->string value)))
|
|
|
|
(define (raco-executable)
|
|
(find-raco-executable))
|
|
|
|
(define (open-racket-documentation search-term)
|
|
(define ok?
|
|
(system* (raco-executable)
|
|
"docs"
|
|
"--"
|
|
search-term))
|
|
(unless ok?
|
|
(raise-arguments-error 'help
|
|
"raco docs failed"
|
|
"search term" search-term)))
|
|
|
|
(define (write-command-list)
|
|
(displayln "rash-coreutils commands:")
|
|
(for ([command (in-list coreutils-commands)])
|
|
(printf " ~a\n" (coreutils-command-name command)))
|
|
(newline)
|
|
(displayln "Use: help <command> or <command> --help")
|
|
(displayln "Other terms are passed to Racket's documentation search."))
|
|
|
|
(define (coreutils-help . args)
|
|
(cond
|
|
[(null? args)
|
|
(write-command-list)]
|
|
[(= (length args) 1)
|
|
(open-racket-documentation
|
|
(coreutils-help-search-term (car args)))]
|
|
[else
|
|
(raise-arguments-error 'help
|
|
"expected zero or one search term"
|
|
"arguments" args)]))
|