add dry-run switch to raco pollen publish

pull/218/head
Matthew Butterick 5 years ago
parent 9f674a4e70
commit f13eec8459

@ -207,12 +207,14 @@ version print the version" (current-server-port) (make-publish-di
(define command-name ; either "publish" or "clone" (define command-name ; either "publish" or "clone"
(vector-ref (current-command-line-arguments) 0)) (vector-ref (current-command-line-arguments) 0))
(define force-target-overwrite? (make-parameter #true)) (define force-target-overwrite? (make-parameter #true))
(define dry-run? (make-parameter #false))
(define other-args (command-line (define other-args (command-line
;; drop command name ;; drop command name
#:argv (vector-drop (current-command-line-arguments) 1) #:argv (vector-drop (current-command-line-arguments) 1)
#:once-each #:once-each
[("-c" "--confirm") "Confirm overwrite of existing dest dir" [("-c" "--confirm") "Confirm overwrite of existing dest dir"
(force-target-overwrite? #f)] (force-target-overwrite? #f)]
[("-d" "--dry-run") "Check paths that would be published" (dry-run? #true)]
#:args other-args #:args other-args
other-args)) other-args))
;; other-args looks like (list [maybe-source-dir-arg] [maybe-dest-dir-arg]) ;; other-args looks like (list [maybe-source-dir-arg] [maybe-dest-dir-arg])
@ -235,7 +237,6 @@ version print the version" (current-server-port) (make-publish-di
(when (equal? dest-dir (current-directory)) (when (equal? dest-dir (current-directory))
(error 'publish "aborted because destination directory for publishing (~a) can't be the same as current directory (~a)" dest-dir (current-directory))) (error 'publish "aborted because destination directory for publishing (~a) can't be the same as current directory (~a)" dest-dir (current-directory)))
(message (string-append (format "publishing from ~a to ~a ..." source-dir dest-dir)))
(define do-publish-operation? (define do-publish-operation?
(or (not (directory-exists? dest-dir)) (or (not (directory-exists? dest-dir))
(force-target-overwrite?) (force-target-overwrite?)
@ -244,6 +245,20 @@ version print the version" (current-server-port) (make-publish-di
(case (read) (case (read)
[(y yes) #true] [(y yes) #true]
[else #false])))) [else #false]))))
(cond
[dry-run?
(message "publish: start dry run")
(message (format "would publish from ~a to ~a" source-dir dest-dir))
(cond
[(directory-exists? dest-dir)
(message (string-append (format "directory ~a exists (but can be overwritten)" dest-dir)))]
[(directory-exists? (simplify-path (build-path dest-dir "..")))
(message (string-append (format "directory ~a does not exist (but can be created)" dest-dir)))]
[else
(raise-user-error 'publish "dry run failure: directory path ~a is defective (neither directory nor parent directory exists)" dest-dir)])
(message "publish: end dry run")]
[else
(message (string-append (format "publishing from ~a to ~a ..." source-dir dest-dir)))
(cond (cond
[do-publish-operation? [do-publish-operation?
(when (directory-exists? dest-dir) (when (directory-exists? dest-dir)
@ -258,7 +273,7 @@ version print the version" (current-server-port) (make-publish-di
(and (omitted-path? p) (not (extra-path? p)))) (and (omitted-path? p) (not (extra-path? p))))
(for-each delete-it! (find-files delete-from-publish-dir? dest-dir))) (for-each delete-it! (find-files delete-from-publish-dir? dest-dir)))
(message "publish completed")] (message "publish completed")]
[else (message "publish aborted")])) [else (message "publish aborted")])]))
(define (handle-unknown command) (define (handle-unknown command)
(match command (match command

@ -1 +1 @@
1582236997 1582753630

@ -159,6 +159,7 @@ You can determine the default publishing destination for a project by overriding
Certain files and directories are automatically omitted from the published directory, including Racket and Pollen sources, Pollen caches, and source-control directories (like @tt{.git} and @tt{.svn}). You can omit other files by overriding @racket[default-omitted-path?]. You can override these omissions — that is, force a path to be published — by overriding @racket[default-extra-path?]. Certain files and directories are automatically omitted from the published directory, including Racket and Pollen sources, Pollen caches, and source-control directories (like @tt{.git} and @tt{.svn}). You can omit other files by overriding @racket[default-omitted-path?]. You can override these omissions — that is, force a path to be published — by overriding @racket[default-extra-path?].
The optional @exec{--dry-run} or @exec{-d} switch prints the source and destination directories for publishing without actually doing so. If the destination-directory path cannot be created, an error will arise.
@section{@exec{raco pollen setup}} @section{@exec{raco pollen setup}}

Loading…
Cancel
Save