Function: majutsu-op-log--validate-args

majutsu-op-log--validate-args is a natively compiled function defined in majutsu-op.el.

Signature

(majutsu-op-log--validate-args ARGS)

Documentation

Return normalized safe operation log ARGS or signal user-error.

Majutsu owns the template and row framing. Only one limit, reverse-order switch, and graph switch are allowed.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-op.el
(defun majutsu-op-log--validate-args (args)
  "Return normalized safe operation log ARGS or signal `user-error'.
Majutsu owns the template and row framing.  Only one limit, reverse-order
switch, and graph switch are allowed."
  (unless (listp args)
    (user-error "Operation log arguments must be a list, got %S" args))
  (let ((rest args)
        (seen (make-hash-table :test #'eq))
        normalized)
    (while rest
      (let ((arg (pop rest)))
        (unless (stringp arg)
          (user-error "Unsupported operation log argument: %S" arg))
        (pcase-let*
            ((`(,kind ,value)
              (cond
               ((string-match "\\`--limit=\\([0-9]+\\)\\'" arg)
                (list 'limit (format "--limit=%s" (match-string 1 arg))))
               ((member arg '("-n" "--limit"))
                (let ((limit (pop rest)))
                  (unless (and (stringp limit)
                               (string-match-p "\\`[0-9]+\\'" limit))
                    (user-error "Invalid operation log limit: %S" limit))
                  (list 'limit (format "--limit=%s" limit))))
               ((equal arg "--reversed")
                '(reversed "--reversed"))
               ((member arg '("-G" "--no-graph"))
                '(no-graph "--no-graph"))
               (t
                (user-error "Unsupported operation log argument: %s" arg)))))
          (when (gethash kind seen)
            (user-error "Duplicate operation log argument: %s" arg))
          (puthash kind t seen)
          (push value normalized))))
    (nreverse normalized)))