improvements

pull/9/head
Matthew Butterick 11 years ago
parent 4b7c237a7a
commit 2e91c41d02

@ -3,26 +3,25 @@
;; Handle commands from raco ;; Handle commands from raco
;; arg 0 will be the command name
(define-for-syntax args (current-command-line-arguments)) (define-for-syntax args (current-command-line-arguments))
(define-for-syntax arg-command-name (with-handlers ([exn:fail? (λ(exn) #f)]) (define-for-syntax arg-command-name (with-handlers ([exn:fail? (λ(exn) #f)]) (vector-ref args 0)))
(vector-ref args 0)))
(define-for-syntax arg-project-directory (define-for-syntax arg-project-directory
(if (> (vector-length args) 1) (with-handlers ([exn:fail? (λ(exn) (current-directory))])
(with-handlers ([exn:fail? (λ(exn) #f)]) (path->complete-path (simplify-path (string->path (vector-ref args 1))))))
(let ([possible-path (path->complete-path (simplify-path (string->path (vector-ref args 1))))])
possible-path))
(current-directory)))
(define-for-syntax (command-error error-string) (define-for-syntax (command-error error-string)
`(displayln (string-append "Error: ", error-string))) `(displayln (string-append "Error: ", error-string)))
;; we work in syntax layer because requiring pollen/server is slow.
(define-syntax (just-a-hook-for-the-macro stx) (define-syntax (just-a-hook-for-the-macro stx)
(if arg-command-name
(datum->syntax stx (datum->syntax stx
(case arg-command-name (case arg-command-name
[("test") `(displayln "All systems go")] [(#f "help") ' (displayln "Pollen commands:
start starts project server
render renders all files in project directory
clone copies rendered files to desktop
[filename] renders individual file")]
[("start") [("start")
(if (not (directory-exists? arg-project-directory)) (if (not (directory-exists? arg-project-directory))
(command-error (format "~a is not a directory" arg-project-directory)) (command-error (format "~a is not a directory" arg-project-directory))
@ -33,34 +32,13 @@
[else (if (regexp-match #rx"(shit|fuck)" arg-command-name) [else (if (regexp-match #rx"(shit|fuck)" arg-command-name)
(displayln (let ([responses '("Cursing at free software? Really?" "How uncouth." "Same to you, buddy.")]) (displayln (let ([responses '("Cursing at free software? Really?" "How uncouth." "Same to you, buddy.")])
(list-ref responses (random (length responses))))) (list-ref responses (random (length responses)))))
(command-error (format "unknown command ~a" arg-command-name)))])) (command-error (format "unknown command ~a" arg-command-name)))])))
#'(begin)))
(just-a-hook-for-the-macro) (just-a-hook-for-the-macro)
#| #|
#lang racket/base
(require (for-syntax racket/base))
;; todo: add command to check validity of installation
(require (for-syntax sugar "world.rkt"))
(define-syntax (handle-pollen-command stx)
(datum->syntax stx
(let* ([args (current-command-line-arguments)]
[arg (if (> (len args) 0) (get args 0) "")])
(display (format "~a: " world:command-file))
(case arg
[("help") (displayln "valid commands are
polcom start (starts project server)
polcom render (renders all files in project directory)
polcom clone (copies rendered files to desktop)
polcom [filename] (renders individual file)")]
[("start") `(require "server.rkt")]
[("render") `(begin [("render") `(begin
;; todo: take extensions off the comand line ;; todo: take extensions off the comand line
(displayln "Render preproc & ptree files ...") (displayln "Render preproc & ptree files ...")

Loading…
Cancel
Save