(declare (unit tick-attach)) (module tick-attach () (import scheme) (import (chicken base) (chicken file) (chicken format) (chicken pathname)) (import commands optimism simple-logger) (import tick) (define-command 'attach "\ attach --ticket|-t [] [ ...] Attach files to ticket identified by (a SHA1 hash or a Trac ticket number). : --clobber|-c Overwrite attachments if they already exist. --delete|-d Delete attachments. Attachments to delete can either be absolute paths or paths relative to the attachment directory of the ticket." (lambda (args*) (let* ((args (parse-command-line args* `(((--ticket -t) . ticket) ((--clobber -c)) ((--delete -d)) ((--) . files) ))) (ticket (get-opt '(--ticket -t) args)) (clobber? (get-opt '(--clobber -c) args flag?: #t)) (delete? (get-opt '(--delete -d) args flag?: #t)) (attachments (get-opt '(--) args))) (when (or (not ticket) (null? attachments)) (show-command-help 'attach 1)) (when (and clobber? delete?) (log-warning "Ignoring --clobber, as --delete was used.")) (let* ((thash (ensure-ticket ticket)) (attachments-dir (ticket-attachments-dir thash))) (set-last-used-ticket-hash! thash) (if delete? (delete-ticket-attachments thash attachments) (add-ticket-attachments thash attachments clobber?)))))) ) ;; end module