Update format stuff
This commit is contained in:
@ -425,25 +425,57 @@ list of trash directories that were present in INFOS."
|
||||
(no-sort infos)
|
||||
(t (sort-trashinfos-for-cmd infos cmd)))))
|
||||
|
||||
(defun print-objects-for-command (cmd objs &optional (indices t) extra-action)
|
||||
(defun print-objects-for-command (cmd objs &key (indices t) extra-action)
|
||||
"Print OBJS, a list of trashinfos or trash directories, for CMD."
|
||||
(if (clingon:getopt cmd :directory-wise)
|
||||
(format-list t (clingon:getopt cmd :dir-format) objs indices extra-action)
|
||||
(format-list t (clingon:getopt cmd :file-format) objs indices extra-action)))
|
||||
(format-list t (clingon:getopt cmd :dir-format) objs
|
||||
:indices indices :extra-action extra-action)
|
||||
(format-list t (clingon:getopt cmd :file-format) objs
|
||||
:indices indices :extra-action extra-action)))
|
||||
|
||||
|
||||
;; List command
|
||||
(defun list/handler (cmd)
|
||||
"Handler for the \"list\" subcommand."
|
||||
(let ((objs (list-objects-for-command cmd)))
|
||||
(print-objects-for-command cmd objs)))
|
||||
(let* ((quiet (clingon:getopt cmd :quiet))
|
||||
(objs (list-objects-for-command cmd quiet))
|
||||
(total (clingon:getopt cmd :total))
|
||||
(dir-wise (clingon:getopt cmd :directory-wise))
|
||||
(total-count 0))
|
||||
(when (and quiet (not total))
|
||||
(error "Can't have -q without -t"))
|
||||
(cond
|
||||
((and quiet dir-wise)
|
||||
(dolist (path-and-infos objs)
|
||||
(incf total-count (length (cdr path-and-infos)))))
|
||||
(quiet (setq total-count (length objs)))
|
||||
(t (print-objects-for-command
|
||||
cmd objs
|
||||
:extra-action (lambda (obj)
|
||||
(incf total-count
|
||||
(if dir-wise (length (cdr obj)) 1))))))
|
||||
(when total
|
||||
(format t "~@[~*Total Matches: ~]~D~%" (not quiet) total-count))))
|
||||
|
||||
(defun list/options ()
|
||||
"Return options for the \"list\" subcommand."
|
||||
(append
|
||||
(clingon-format-options "%t %o\\n" "Found %c file%m in %p\\n")
|
||||
(clingon-filtering-options)
|
||||
(clingon-sort-options)))
|
||||
(clingon-sort-options)
|
||||
(list
|
||||
(clingon:make-option
|
||||
:flag
|
||||
:key :total
|
||||
:description "print a total after all matches"
|
||||
:short-name #\t
|
||||
:long-name "total")
|
||||
(clingon:make-option
|
||||
:flag
|
||||
:key :quiet
|
||||
:description "suppress print matches (use with -t)"
|
||||
:short-name #\q
|
||||
:long-name "quiet"))))
|
||||
|
||||
(defun list/command ()
|
||||
"Return the Clingon command for the \"list\" subcommand."
|
||||
@ -592,7 +624,7 @@ return a list of many indices instead."
|
||||
(when (and indices all)
|
||||
(error "Can't use -a and -n together"))
|
||||
(unless (or yes quiet)
|
||||
(print-objects-for-command cmd objs (or indices t)))
|
||||
(print-objects-for-command cmd objs :indices (or indices t)))
|
||||
(cond
|
||||
((not objs) (unless quiet
|
||||
(error "Nothing to do...")))
|
||||
@ -797,7 +829,8 @@ return a list of many indices instead."
|
||||
(dir-wise (clingon:getopt cmd :directory-wise))
|
||||
(base-two (clingon:getopt cmd :base-two))
|
||||
(bytes (clingon:getopt cmd :bytes))
|
||||
(total-size 0))
|
||||
(total-size 0)
|
||||
(*format-switch-base-two-base-ten* base-two))
|
||||
(when (and bytes base-two)
|
||||
(error "Can't pass both -t and -b"))
|
||||
(flet ((sum (size)
|
||||
@ -812,14 +845,14 @@ return a list of many indices instead."
|
||||
(sum (trashinfo-size info))))
|
||||
(dir-wise
|
||||
(print-objects-for-command
|
||||
cmd objs t (lambda (path-and-infos)
|
||||
(dolist (info (cdr path-and-infos))
|
||||
(sum (trashinfo-size info))))))
|
||||
cmd objs :extra-action (lambda (path-and-infos)
|
||||
(dolist (info (cdr path-and-infos))
|
||||
(sum (trashinfo-size info))))))
|
||||
(t
|
||||
(print-objects-for-command
|
||||
cmd objs t (lambda (info)
|
||||
(sum (trashinfo-size info)))))))
|
||||
(format t "~@[~*Total Size: ~]~A"
|
||||
cmd objs :extra-action (lambda (info)
|
||||
(sum (trashinfo-size info)))))))
|
||||
(format t "~@[~*Total Size: ~]~D~%"
|
||||
(not quiet) (if bytes
|
||||
total-size
|
||||
(format-size total-size base-two)))))
|
||||
@ -834,7 +867,8 @@ return a list of many indices instead."
|
||||
(clingon:make-option
|
||||
:flag
|
||||
:key :base-two
|
||||
:description "use base two sizes for the final tally"
|
||||
:description
|
||||
"use base two sizes for the final tally (also switch %h and %H format codes)"
|
||||
:short-name #\t
|
||||
:long-name "base-two")
|
||||
(clingon:make-option
|
||||
|
||||
Reference in New Issue
Block a user