From 945cfd0889ed883e307ddc2404b267d25dbc4f60 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Mon, 6 Apr 2020 15:27:08 -0700 Subject: [PATCH] raco command --- words/command.rkt | 59 +++++++++++++++++++++++++++++++++++++++++++++++ words/index.rkt | 1 + words/info.rkt | 3 ++- words/main.rkt | 7 ++++-- 4 files changed, 67 insertions(+), 3 deletions(-) create mode 100755 words/command.rkt diff --git a/words/command.rkt b/words/command.rkt new file mode 100755 index 0000000..a7dfdaf --- /dev/null +++ b/words/command.rkt @@ -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) " "))) + + diff --git a/words/index.rkt b/words/index.rkt index 2a65ed4..51da572 100644 --- a/words/index.rkt +++ b/words/index.rkt @@ -76,4 +76,5 @@ (λ () (fasl->s-exp (current-input-port)))))) (define (post-installer home-dir) + (displayln "running words post-installer") (regenerate-word-index!)) \ No newline at end of file diff --git a/words/info.rkt b/words/info.rkt index fdffd01..b46441f 100644 --- a/words/info.rkt +++ b/words/info.rkt @@ -1,3 +1,4 @@ #lang info -(define post-install-collection "index.rkt") \ No newline at end of file +(define post-install-collection "index.rkt") +(define raco-commands '(("words" (submod words/command raco) "issue words command" #f))) diff --git a/words/main.rkt b/words/main.rkt index 29cd069..1706976 100644 --- a/words/main.rkt +++ b/words/main.rkt @@ -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)