mcfly-tools-msg.rkt
#lang racket/base
;; Copyright Neil Van Dyke.  See file "info.rkt".

;; TODO: Decide which code uses these messages and which code is reusable
;; procedures that may be used from other than command-line interfaces.  Maybe
;; have a "current-command-line-messages?" parameter or similar to enable or
;; disable helpful diagnostics (such as when doc.scrbl is generated.

(provide current-verbose-msg?)
(define current-verbose-msg? (make-parameter #f))

(provide msg/port/prefix)
(define (msg/port/prefix port prefix format . args)
  (apply fprintf
         port
         ;; (string-append "~A: ~A" format "\n")
         ;; (current-program)
         (string-append "raco mcfly: ~A" format "\n")
         prefix
         args))

(provide msg-info)
(define (msg-info format . args)
  (apply msg/port/prefix
         (current-output-port)
         ""
         format
         args))

(provide msg-warning)
(define (msg-warning format . args)
  (apply msg/port/prefix
         (current-error-port)
         "Warning: "
         format
         args))

(provide msg-error)
(define (msg-error format . args)
  (apply msg/port/prefix
         (current-error-port)
         "Error: "
         format
         args))

(provide msg-debug)
(define (msg-debug format . args)
  (apply msg/port/prefix
         (current-error-port)
         "*DEBUG* "
         format
         args))

(provide msg-verbose)
(define (msg-verbose format . args)
  (if (current-verbose-msg?)
      (apply msg-info format args)
      (void)))

(provide fatal-command-line-error)
(define (fatal-command-line-error format . args)
  (apply msg-error format args)
  (exit 1))