(define (die msg) (begin (write msg) (exit 1))) (define (usage) (die "increment_version [position]\n\tposition defaults to 2")) (define (parse-args) (cond ((eq? 0 (length zepto:args)) 2) ((and (string:num? (car zepto:args)) (eq? 1 (length zepto:args))) (string->number (car zepto:args))) (else (usage)))) (define (main position) (if (not (file-exists? "VERSION")) (die "A version file is needed in the current directory") (let* ((version (read-contents "VERSION")) (new-version (|> (string:split version ".") (curry map string->number) list->vector ($ (vector:update % position add1)) (curry vector:map number->string) ($ (string:join % "."))))) (with-output-file "VERSION" (curry write new-version))))) (main (parse-args)) (exit 0)