Option parsing
This commit is contained in:
parent
58229a58ab
commit
1ed4ef1115
3 changed files with 53 additions and 4 deletions
1
Makefile
1
Makefile
|
|
@ -65,6 +65,7 @@ $(LIBS): $(QL)/setup.lisp
|
|||
--eval '(ql:quickload :alexandria)' \
|
||||
--eval '(ql:quickload :fiveam)' \
|
||||
--eval '(ql:quickload :deploy)' \
|
||||
--eval '(ql:quickload :clingon)' \
|
||||
--eval '(quit)'
|
||||
touch $@
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@
|
|||
:serial t
|
||||
:build-operation "program-op"
|
||||
:entry-point "pegrep:entry"
|
||||
:depends-on ("alexandria")
|
||||
:depends-on (:alexandria :clingon)
|
||||
:components
|
||||
((:module "./src"
|
||||
:serial t
|
||||
|
|
@ -52,7 +52,7 @@
|
|||
:build-pathname "pegrep-deploy"
|
||||
:build-operation "deploy-op"
|
||||
:entry-point "pegrep:entry"
|
||||
:depends-on ("alexandria")
|
||||
:depends-on (:alexandria :clingon)
|
||||
:components
|
||||
((:module "./src"
|
||||
:serial t
|
||||
|
|
|
|||
|
|
@ -1,8 +1,56 @@
|
|||
(defpackage :pegrep
|
||||
(:use :cl :alexandria)
|
||||
(:use :cl :alexandria :clingon)
|
||||
(:local-nicknames (:cli :clingon))
|
||||
(:export :entry))
|
||||
|
||||
(in-package :pegrep)
|
||||
|
||||
(defun pegrep/options ()
|
||||
(list
|
||||
(cli:make-option
|
||||
:string
|
||||
:description "Whitespace regexp"
|
||||
:short-name #\w
|
||||
:long-name "whitespace"
|
||||
:key :whitespace)
|
||||
(cli:make-option
|
||||
:boolean/true
|
||||
:description "Use default whitespace"
|
||||
:short-name #\W
|
||||
:key :whitespace)
|
||||
(cli:make-option
|
||||
:list
|
||||
:description "Config Files"
|
||||
:short-name #\c
|
||||
:key :cfg-files)
|
||||
(cli:make-option
|
||||
:string
|
||||
:required t
|
||||
:description "PEG Expression"
|
||||
:short-name #\e
|
||||
:key :expr)))
|
||||
|
||||
(defun pegrep/handler (cmd)
|
||||
(format t "Hello, world!~%")
|
||||
(format t "Whitespace Value: \"~a\"~%"
|
||||
(let ((ws (cli:getopt cmd :whitespace)))
|
||||
(cond ((stringp ws)
|
||||
ws)
|
||||
((eq ws t)
|
||||
"[ \\t\\n\\r]*")
|
||||
(t ""))))
|
||||
(format t "Config Files: ~a~%"
|
||||
(cli:getopt cmd :cfg-files))
|
||||
(format t "PEG Expression: ~a~%"
|
||||
(cli:getopt cmd :expr)))
|
||||
|
||||
(defun pegrep/command ()
|
||||
(cli:make-command
|
||||
:name "pegrep"
|
||||
:description "when regular expressions aren't enough!"
|
||||
:options (pegrep/options)
|
||||
:handler #'pegrep/handler))
|
||||
|
||||
(defun entry ()
|
||||
(format t "Hello, world!~%"))
|
||||
(let ((cmd (pegrep/command)))
|
||||
(cli:run cmd)))
|
||||
|
|
|
|||
Loading…
Reference in a new issue