Add missing eval-when clause.
[clon.git] / demos / simple.lisp
blob68611e16db23fda6c7554a8f805aa8a4283b9f79
1 ;;; simple.lisp --- Basic usage demonstration program
3 ;; Copyright (C) 2010 Didier Verna
5 ;; Author: Didier Verna <didier@lrde.epita.fr>
6 ;; Maintainer: Didier Verna <didier@lrde.epita.fr>
7 ;; Created: Fri Aug 1 14:45:48 2008
8 ;; Last Revision: Sun Oct 31 14:21:33 2010
10 ;; This file is part of Clon.
12 ;; Clon is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License version 3,
14 ;; as published by the Free Software Foundation.
16 ;; Clon is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; if not, write to the Free Software
23 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 ;;; Commentary:
28 ;; Contents management by FCM version 0.1.
30 ;; This demonstration program shows how to define your application's
31 ;; command-line syntax, initialize the library, retrieve option values and
32 ;; generate help strings.
35 ;;; Code:
37 (in-package :cl-user)
39 (require :asdf
40 #-(or sbcl cmu ccl ecl)
41 '(#p"/usr/local/share/common-lisp/source/asdf/asdf.lisp"))
43 #-asdf2 (setf asdf:*central-registry*
44 (list* (merge-pathnames "share/common-lisp/systems/"
45 (user-homedir-pathname))
46 #p"/usr/local/share/common-lisp/systems/"
47 #p"/usr/share/common-lisp/systems/"
48 asdf:*central-registry*))
50 #-asdf2 (ignore-errors (asdf:operate 'asdf:load-op :asdf-binary-locations))
52 (asdf:operate 'asdf:load-op :com.dvlsoft.clon)
53 (eval-when (:execute :load-toplevel :compile-toplevel) ;; ECL needs this.
54 (com.dvlsoft.clon:nickname-package))
56 (clon:defsynopsis (:postfix "FILES...")
57 (text :contents
58 "Demonstration of Clon (use --clon-help for built-in options).")
59 (group (:header "Flags (non valued options):")
60 (flag :short-name "h" :long-name "help"
61 :description "Print this help and exit."))
62 (group (:header "Built-in valued option types:")
63 (group (:header "String options:")
64 (stropt :short-name "n" :long-name "name"
65 :description "Set your name to NAME."
66 :argument-name "NAME"))
67 (group (:header "Lisp objects:")
68 (lispobj :short-name "e" :long-name "eval"
69 :description "Evaluate EXPR."
70 :argument-name "EXPR"))
71 (group (:header "Enumerations:")
72 (enum :long-name "copyright"
73 :description "Set the copyright to LICENSE.
74 Possible values are: none, gpl, lppl, bsd or mit."
75 :argument-name "LICENSE"
76 :argument-type :optional
77 :enum '(:none :gpl :lppl :bsd :mit)
78 :fallback-value :gpl
79 :default-value :none))
80 (group (:header "Path options:")
81 (path :long-name "tmpdir"
82 :description "Set the temporary directory to DIR."
83 :argument-name "DIR"
84 :type :directory
85 :default-value #p"/tmp/")
86 (path :short-name "o" :long-name "output"
87 :description "Output to FILE."
88 :argument-name "FILE"
89 :type :file
90 :default-value #p"a.out")
91 (path :short-name "I"
92 :description "Set the include search path to SEARCH-PATH.
93 SEARCH-PATH is a colon-separated list of directories. Use an empty argument to
94 remove all search paths."
95 :argument-name "SEARCH-PATH"
96 :type :directory-list
97 :default-value '(#p"/usr/local/share/" #p"/usr/share/")))
98 (group (:header "Switches:")
99 (switch :short-name "d" :long-name "debug"
100 :description "Turn debugging on or off."
101 :argument-style :on/off
102 :env-var "DEBUG"))
103 (group (:header "Extended switches:")
104 (xswitch :short-name "c" :long-name "connect"
105 :description "Connect to server.
106 Possible values are yes, no or try. If try, no errors are reported."
107 :enum '(:try)))))
109 (defun main ()
110 "Entry point for the standalone application."
111 (clon:make-context)
112 (cond ((clon:getopt :short-name "h")
113 (clon:help))
115 (format t "Program name: ~A~%~%" (clon:progname))
116 (format t "Options:")
117 (clon:do-cmdline-options (option name value source)
118 (print (list option name value source)))
119 (terpri)
120 (format t "Remainder: ~A~%" (clon:remainder))))
121 (clon:exit))
123 (clon:dump "simple" #'main)
126 ;;; simple.lisp ends here