1(in-package #:cl-user)
2
3;;;; Licensed under the Apache License, Version 2.0 (the "License");
4;;;; you may not use this file except in compliance with the License.
5;;;; You may obtain a copy of the License at
6;;;;
7;;;;     http://www.apache.org/licenses/LICENSE-2.0
8;;;;
9;;;; Unless required by applicable law or agreed to in writing, software
10;;;; distributed under the License is distributed on an "AS IS" BASIS,
11;;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12;;;; See the License for the specific language governing permissions and
13;;;; limitations under the License.
14
15(require "asdf")
16(load (merge-pathnames "../../lib/cl/load-locally.lisp" *load-truename*))
17(require "sb-grovel") ;; necessary for :net.didierverna.clon.termio
18(asdf:load-asd (first (directory (merge-pathnames "../../lib/cl/externals/software/clon-*/termio/net.didierverna.clon.termio.asd"
19                                                  *load-truename*))))
20(asdf:load-system :net.didierverna.clon)
21(asdf:load-asd (merge-pathnames "gen-cl/ThriftTest/thrift-gen-ThriftTest.asd" *load-truename*))
22(asdf:load-system :thrift-gen-thrifttest)
23(load (merge-pathnames "implementation.lisp" *load-truename*))
24
25(net.didierverna.clon:nickname-package)
26
27(clon:defsynopsis ()
28  (text :contents "The Common Lisp server for Thrift's cross-language test suite.")
29  (group (:header "Allowed options:")
30    (flag :short-name "h" :long-name "help"
31          :description "Print this help and exit.")
32    (stropt :long-name "port"
33            :description "Number of the port to listen for connections on."
34            :default-value "9090"
35            :argument-name "ARG"
36            :argument-type :optional)
37    (stropt :long-name "server-type"
38            :description "The type of server, currently only \"simple\" is available."
39            :default-value "simple"
40            :argument-name "ARG")
41    (stropt :long-name "transport"
42            :description "Transport: transport to use (\"buffered\" or \"framed\")"
43            :default-value "buffered"
44            :argument-name "ARG")
45    (stropt :long-name "protocol"
46            :description "Protocol: protocol to use (\"binary\" or \"multi\")"
47            :default-value "binary"
48            :argument-name "ARG")))
49
50(defun main ()
51  "Entry point for our standalone application."
52  (clon:make-context)
53  (when (clon:getopt :short-name "h")
54    (clon:help)
55    (clon:exit))
56  (let ((port "9090")
57        (framed nil)
58        (multiplexed nil))
59    (clon:do-cmdline-options (option name value source)
60      (print (list option name value source))
61      (if (string= name "port")
62          (setf port value))
63      (if (string= name "transport")
64          (cond ((string= value "buffered") (setf framed nil))
65                ((string= value "framed") (setf framed t))
66                (t (error "Unsupported transport."))))
67      (if (string= name "protocol")
68          (cond ((string= value "binary") (setf multiplexed nil))
69                ((string= value "multi") (setf multiplexed t))
70                (t (error "Unsupported protocol.")))))
71    (terpri)
72    (let ((services (if multiplexed
73                        (list thrift.test:thrift-test thrift.test:second-service)
74                        thrift.test:thrift-test)))
75      (thrift:serve (puri:parse-uri (concatenate 'string
76                                                 "thrift://127.0.0.1:"
77                                                 port))
78                    services
79                    :framed framed
80                    :multiplexed multiplexed)))
81  (clon:exit))
82
83(clon:dump "TestServer" main)
84