(functor ; functor and argument ((awful main) (S (run))) ; exports () ; imports (import (scheme) (only (awful) awful-start) (only (chicken base) error print unless) (only (chicken format) sprintf) (only (chicken pathname) pathname-directory) (only (chicken process-context) executable-pathname command-line-arguments) (only (chicken string) string-split) (prefix (spiffy) sp:) (prefix (S) site:)) (define (print-usage) (print " Usage: ./example/main [OPTIONS] --user=user User to drop privileges to --addr=address Address to bind to [127.0.0.1] --port=port Port to bind to [8080] --access-log=path Access log path [/usr/home/gahr/fossil/awful-main/example/access.log] --debug-log=path Debug log path --error-log=path Error log path [/usr/home/gahr/fossil/awful-main/example/error.log] --web-root=path Web-root path --dev Run awful in development mode --args Pass additional arguments to site:run")) (define (check arg val) (if (pair? val) (car val) (error "Missing required argument" arg))) (define root (pathname-directory (executable-pathname))) (let loop ((rest (command-line-arguments)) (user #f) (addr "127.0.0.1") (port 8080) (access-log (sprintf "~A/access.log" root)) (debug-log #f) (error-log (sprintf "~A/error.log" root)) (web-root (sprintf "~A/static" root)) (dev #f) (args #f) (extras '())) (if (null? rest) (begin ; setup (sp:root-path web-root) (sp:spiffy-user user) (sp:server-bind-address addr) (sp:server-port port) (sp:access-log access-log) (if debug-log (sp:debug-log debug-log)) (sp:error-log error-log) ; off we go... (awful-start (lambda () (if args (site:run (reverse extras)) (site:run))) dev-mode?: dev)) (begin (let* ((this (car rest)) (rest (cdr rest)) (pair (string-split this "=")) (key (car pair)) (val (cdr pair))) (case (string->symbol key) ((|--user|) (let ((value (check '--addr val))) (loop rest value addr port access-log debug-log error-log web-root dev args extras))) ((|--addr|) (let ((value (check '--addr val))) (loop rest user value port access-log debug-log error-log web-root dev args extras))) ((|--port|) (let ((value (check '--port val))) (loop rest user addr (string->number value) access-log debug-log error-log web-root dev args extras))) ((|--access-log|) (let ((value (check '--access-log val))) (loop rest user addr port value debug-log error-log web-root dev args extras))) ((|--debug-log|) (let ((value (check '--debug-log val))) (loop rest user addr port access-log value error-log web-root dev args extras))) ((|--error-log|) (let ((value (check '--error-log val))) (loop rest user addr port access-log debug-log value web-root dev args extras))) ((|--web-root|) (let ((value (check '--web-root val))) (loop rest user addr port access-log debug-log error-log value dev args extras))) ((|--dev|) (loop rest user addr port access-log debug-log error-log web-root #t args extras)) ((|--args|) (loop rest user addr port access-log debug-log error-log web-root dev #t extras)) ((|--help|) (print-usage)) (else (if args (loop rest user addr port access-log debug-log error-log web-root dev args (cons this extras)) (error "unexpected argument" key)))))))) )