From b2a27cd4dfc506c6028fb4d4b06e935f7ee95783 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 14 Mar 2014 15:36:02 -0700 Subject: [PATCH] support multiple server ports --- command.rkt | 5 +++-- raco.rkt | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/command.rkt b/command.rkt index ba49f7a..6f0a184 100644 --- a/command.rkt +++ b/command.rkt @@ -9,12 +9,13 @@ render renders all files in project directory clone copies rendered files to desktop [filename] renders individual file")) -(define (handle-start directory) +(define (handle-start directory [port #f]) (if (not (directory-exists? directory)) (error (format "~a is not a directory" directory)) `(begin (require pollen/server pollen/world) - (parameterize ([world:current-project-root ,directory]) + (parameterize ([world:current-project-root ,directory] + ,@(if port (list `(world:current-server-port ,port)) null)) (start-server))))) (define (handle-else command) diff --git a/raco.rkt b/raco.rkt index 51aa1bd..6e49731 100644 --- a/raco.rkt +++ b/raco.rkt @@ -6,10 +6,15 @@ (define-for-syntax args (current-command-line-arguments)) (define-for-syntax arg-command-name (with-handlers ([exn:fail? (λ(exn) #f)]) (vector-ref args 0))) + (define-for-syntax arg-project-directory (with-handlers ([exn:fail? (λ(exn) (current-directory))]) (path->complete-path (simplify-path (string->path (vector-ref args 1)))))) +(define-for-syntax arg-server-port + (with-handlers ([exn:fail? (λ(exn) #f)]) + (string->number (vector-ref args 2)))) + (define-for-syntax (command-error error-string) `(displayln (string-append "Error: ", error-string))) @@ -19,7 +24,7 @@ (datum->syntax stx (case arg-command-name [(#f "help") (handle-help)] - [("start") (handle-start arg-project-directory)] + [("start") (handle-start arg-project-directory arg-server-port)] [else (handle-else arg-command-name)]))) (select-syntax-for-command)