options.lisp (1081B)
1 (in-package :cl-grep) 2 3 ;; Adapted from original unix-opts example: 4 ;; https://github.com/libre-man/unix-opts/blob/master/example/example.lisp 5 6 (opts:define-opts 7 (:name :num-workers 8 :description "Number of core grep worker threads to spawn" 9 :short #\j 10 :long "jobs" 11 :arg-parser #'parse-integer 12 :meta-var "JOBS") 13 (:name :mmap 14 :description "Whether to enable mmap based file processing" 15 :short #\m 16 :long "mmap") 17 (:name :chunk-size 18 :description "Size of chunks to load when mmaping" 19 :short #\c 20 :long "chunksize" 21 :arg-parser #'parse-integer 22 :meta-var "CHUNKSIZE")) 23 24 (defun process-options (raw-args) 25 (multiple-value-bind (options free-args) 26 (handler-case (opts:get-opts raw-args) 27 (opts:unknown-option (c) 28 (format t "Unknown option: ~a. Aborting!" (opts:option c)) 29 (opts:exit 1))) 30 ;; deal with the options here 31 (aif (getf options :jobs) 32 (setf +numw+ it)) 33 (if (getf options :mmap) 34 (setf grep-file-mode 'mmap)) 35 (aif (getf options :chunk-size) 36 (setf +chunk-size+ it)) 37 free-args))