1 ;;; advanced.lisp --- Advanced usage demonstration program
3 ;; Copyright (C) 2010, 2011, 2012 Didier Verna.
5 ;; Author: Didier Verna <didier@lrde.epita.fr>
6 ;; Maintainer: Didier Verna <didier@lrde.epita.fr>
8 ;; This file is part of Clon.
10 ;; Permission to use, copy, modify, and distribute this software for any
11 ;; purpose with or without fee is hereby granted, provided that the above
12 ;; copyright notice and this permission notice appear in all copies.
14 ;; THIS SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 ;; Contents management by FCM version 0.1.
27 ;; This demonstration program shows how to use multiple synopsis, contexts and
28 ;; (virtual) command-lines in the same application in order to manage more
29 ;; complex command-line syntax where options and non-options parts can be
30 ;; freely intermixed. See section 5 "Advanced Usage" in the Clon User Manual.
32 ;; #### NOTE: some trickery is needed below in order to make this code
33 ;; ECL-compliant, due to ECL's specific way of generating executables. This
35 ;; - setting *load-verbose* to nil,
36 ;; - passing a nil :verbose flag to asdf:load-system,
37 ;; - wrapping nickname-package in an eval-when form.
38 ;; None of these tweaks are needed for the other compilers.
45 (setq *load-verbose
* nil
)
49 #-
(or sbcl cmu ccl ecl allegro
50 (and lispworks
(not lispworks-personal-edition
)))
51 '(#p
"/usr/local/share/common-lisp/source/asdf/asdf.lisp"))
53 (asdf:load-system
:com.dvlsoft.clon
:verbose nil
)
55 (eval-when (:execute
:load-toplevel
:compile-toplevel
)
56 (com.dvlsoft.clon
:nickname-package
))
58 (clon:defsynopsis
(:postfix
"cmd [OPTIONS]")
59 (text :contents
"Available commands: push pull.
60 Use 'cmd --help' to get command-specific help.")
61 (flag :short-name
"h" :long-name
"help"
62 :description
"Print this help and exit.")
63 (switch :short-name
"d" :long-name
"debug"
64 :description
"Turn debugging on or off."
65 :argument-style
:on
/off
68 (defconstant +push-synopsis
+
69 (clon:defsynopsis
(:make-default nil
)
70 (text :contents
"Push local changes to the remote server.")
71 (flag :short-name
"h" :long-name
"help"
72 :description
"Print this help and exit.")
73 (flag :short-name
"d" :long-name
"dry-run"
74 :description
"Fake the push operation.")
75 (stropt :long-name
"remote"
76 :argument-name
"SERVER"
77 :description
"Use SERVER instead of default remote."))
78 "The synopsis for the PUSH operation.")
80 (defconstant +pull-synopsis
+
81 (clon:defsynopsis
(:make-default nil
)
82 (text :contents
"Pull remote changes to the local server.")
83 (flag :short-name
"h" :long-name
"help"
84 :description
"Print this help and exit.")
85 (flag :short-name
"d" :long-name
"dry-run"
86 :description
"Fake the push operation.")
87 (switch :long-name
"update"
89 :description
"Also update the working directory."))
90 "The synopsis for the PULL operation.")
94 "Entry point for the standalone application."
96 (cond ((or (clon:getopt
:short-name
"h")
97 (not (clon:cmdline-p
)))
100 (unless (clon:remainder
)
101 (format t
"Missing command.~%")
104 :synopsis
(cond ((string= (first (clon:remainder
)) "push")
106 ((string= (first (clon:remainder
)) "pull")
109 (format t
"Unknown command.~%")
111 :cmdline
(clon:remainder
))
112 (cond ((clon:getopt
:short-name
"h")
115 (format t
"Command name: ~A~%~%" (clon:progname
))
116 (format t
"Options:")
117 (clon:do-cmdline-options
(option name value source
)
118 (print (list option name value source
)))
120 (format t
"Remainder: ~A~%" (clon:remainder
))))))
123 (clon:dump
"advanced" main
)
126 ;;; advanced.lisp ends here