raco command

master
Matthew Butterick 5 years ago
parent 4f20d6da3e
commit 945cfd0889

@ -0,0 +1,59 @@
#lang debug racket
(require racket/string
"main.rkt")
(module+ raco
(define command-name (with-handlers ([exn:fail? (λ (exn) #f)])
(vector-ref (current-command-line-arguments) 0)))
(dispatch command-name))
(module+ main
(println "this is words command"))
(define (dispatch command-name)
(define letters "abcdefghijklmnopqrstuvwxyz")
(define mandatory #false)
(define combo #false)
(define min-size #false)
(define max-size #false)
(define max-words #false)
(define hide-plurals #true)
(define proper-names #false)
(command-line
#:program "words"
#:argv (current-command-line-arguments)
#:once-each
[("-l" "--letters") letters-arg
"possible letters (default is a-z)"
(set! letters letters-arg)]
[("-m" "--mandatory") mandatory-arg
"mandatory letters"
(set! mandatory mandatory-arg)]
[("-c" "--combo") combo-arg
"mandatory combo"
(set! combo combo-arg)]
[("-n" "--number") max-words-arg
"max number of results"
(set! max-words (string->number max-words-arg))]
[("--min") min-size-arg
"minimum word lengths"
(set! min-size (string->number min-size-arg))]
[("--max") max-size-arg
"minimum word lengths"
(set! max-size (string->number max-size-arg))]
[("-s" "--show-plurals")
"show plural words"
(set! hide-plurals #false)]
[("-p" "--proper-names")
"show proper names"
(set! proper-names #true)])
(displayln (string-join (make-words #:letters letters
#:mandatory mandatory
#:combo combo
#:max-words max-words
#:min min-size
#:max max-size
#:hide-plurals hide-plurals
#:proper-names proper-names) " ")))

@ -76,4 +76,5 @@
(λ () (fasl->s-exp (current-input-port))))))
(define (post-installer home-dir)
(displayln "running words post-installer")
(regenerate-word-index!))

@ -1,3 +1,4 @@
#lang info
(define post-install-collection "index.rkt")
(define post-install-collection "index.rkt")
(define raco-commands '(("words" (submod words/command raco) "issue words command" #f)))

@ -1,12 +1,13 @@
#lang debug racket/base
(require racket/list
"index.rkt")
(provide make-words)
(define (make-words #:letters [letters "etaoinshrdluw"]
#:mandatory [mandatory #f]
#:combo [combo #f]
#:min [min-length 5]
#:max [max-length 10]
#:min [min-length-arg 5]
#:max [max-length-arg 10]
#:hide-plurals [hide-plurals? #t]
#:proper-names [proper-names? #f]
#:max-words [max-words 10]
@ -31,6 +32,8 @@
[all-caps? string-upcase]
[initial-caps? string-titlecase]
[else values]))
(define min-length (or min-length-arg 0))
(define max-length (or max-length-arg +inf.0))
(for*/fold ([word-acc null]
[count 0]
#:result word-acc)

Loading…
Cancel
Save