adopt/reference/index.html @ e1a7aced6cbf

adopt: Update site.
author Steve Losh <steve@stevelosh.com>
date Fri, 17 May 2019 23:17:29 -0400
parents 9918f80ae953
children 4e63e2f5d2cf
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"/>
        <title> API Reference / Adopt</title>
        <link rel="stylesheet" href="../_dmedia/tango.css"/>
        <link rel="stylesheet/less" type="text/css" href="../_dmedia/style.less"/>
        <script src="../_dmedia/less.js" type="text/javascript">
        </script>
    </head>
    <body class="content">
        <div class="wrap">
            <header><h1><a href="..">Adopt</a></h1></header>
                <div class="markdown">
<h1 id="api-reference"><a href="">API Reference</a></h1><p>The following is a list of all user-facing parts of adopt.</p>
<p>If there are backwards-incompatible changes to anything listed here, they will
be noted in the changelog and the author will feel bad.</p>
<p>Anything not listed here is subject to change at any time with no warning, so
don't touch it.</p>
<div class="toc">
<ul>
<li><a href="#package-adopt">Package ADOPT</a><ul>
<li><a href="#argv-function">ARGV (function)</a></li>
<li><a href="#collect-function">COLLECT (function)</a></li>
<li><a href="#define-string-macro">DEFINE-STRING (macro)</a></li>
<li><a href="#discard-option-function">DISCARD-OPTION (function)</a></li>
<li><a href="#exit-function">EXIT (function)</a></li>
<li><a href="#first-function">FIRST (function)</a></li>
<li><a href="#flip-function">FLIP (function)</a></li>
<li><a href="#last-function">LAST (function)</a></li>
<li><a href="#make-group-function">MAKE-GROUP (function)</a></li>
<li><a href="#make-interface-function">MAKE-INTERFACE (function)</a></li>
<li><a href="#make-option-function">MAKE-OPTION (function)</a></li>
<li><a href="#parse-options-function">PARSE-OPTIONS (function)</a></li>
<li><a href="#print-error-and-exit-function">PRINT-ERROR-AND-EXIT (function)</a></li>
<li><a href="#print-help-function">PRINT-HELP (function)</a></li>
<li><a href="#print-help-and-exit-function">PRINT-HELP-AND-EXIT (function)</a></li>
<li><a href="#print-manual-function">PRINT-MANUAL (function)</a></li>
<li><a href="#supply-new-value-function">SUPPLY-NEW-VALUE (function)</a></li>
<li><a href="#treat-as-argument-function">TREAT-AS-ARGUMENT (function)</a></li>
<li><a href="#unrecognized-option-class">UNRECOGNIZED-OPTION (class)</a><ul>
<li><a href="#slot-problematic-option">Slot PROBLEMATIC-OPTION</a></li>
</ul>
</li>
</ul>
</li>
</ul></div>
<h2 id="package-adopt">Package <code>ADOPT</code></h2>
<h3 id="argv-function"><code>ARGV</code> (function)</h3>
<div class="codehilite"><pre><span/>(ARGV)
</pre></div>


<p>Return a list of the program name and command line arguments.</p>
<p>This is not implemented for every Common Lisp implementation.  You can always
  pass your own values to <code>parse-options</code> and <code>print-help</code> if it's not
  implemented for your particular Lisp.</p>
<h3 id="collect-function"><code>COLLECT</code> (function)</h3>
<div class="codehilite"><pre><span/>(COLLECT LIST EL)
</pre></div>


<p>Append element <code>el</code> to the end of <code>list</code>.</p>
<p>It is useful as a <code>:reduce</code> function when you want to collect all values given
  for an option.</p>
<p>This is implemented as <code>(append list (list el))</code>.  It is not particularly
  fast.  If you can live with reversed output consider <code>(flip #'cons)</code>  instead.</p>
<h3 id="define-string-macro"><code>DEFINE-STRING</code> (macro)</h3>
<div class="codehilite"><pre><span/>(DEFINE-STRING VAR STRING &amp;REST ARGS)
</pre></div>


<p>Convenience macro for <code>(defparameter ,var (format nil ,string ,@args))</code>.</p>
<h3 id="discard-option-function"><code>DISCARD-OPTION</code> (function)</h3>
<div class="codehilite"><pre><span/>(DISCARD-OPTION CONDITION)
</pre></div>


<p>Invoke the <code>discard-option</code> restart properly.</p>
<p>Example:</p>
<div class="codehilite"><pre><span/>(handler-bind ((unrecognized-option 'discard-option))
  (multiple-value-bind (arguments options) (parse-options *ui*)
    (run arguments options)))
</pre></div>


<h3 id="exit-function"><code>EXIT</code> (function)</h3>
<div class="codehilite"><pre><span/>(EXIT &amp;OPTIONAL (CODE 0))
</pre></div>


<h3 id="first-function"><code>FIRST</code> (function)</h3>
<div class="codehilite"><pre><span/>(FIRST OLD NEW)
</pre></div>


<p>Return <code>new</code> if <code>old</code> is <code>nil</code>, otherwise return <code>old</code>.</p>
<p>It is useful as a <code>:reduce</code> function when you want to just keep the
  first-given value for an option.</p>
<h3 id="flip-function"><code>FLIP</code> (function)</h3>
<div class="codehilite"><pre><span/>(FLIP FUNCTION)
</pre></div>


<p>Return a function of two arguments X and Y that calls <code>function</code> with Y and X.</p>
<p>Useful for wrapping existing functions that expect their arguments in the
  opposite order.</p>
<p>Examples:</p>
<div class="codehilite"><pre><span/>(funcall #'cons 1 2)        ; =&gt; (1 . 2)
(funcall (flip #'cons) 1 2) ; =&gt; (2 . 1)
(reduce (flip #'cons) '(1 2 3) :initial-value nil)
; =&gt; (3 2 1)
</pre></div>


<h3 id="last-function"><code>LAST</code> (function)</h3>
<div class="codehilite"><pre><span/>(LAST OLD NEW)
</pre></div>


<p>Return <code>new</code>.</p>
<p>It is useful as a <code>:reduce</code> function when you want to just keep the last-given
  value for an option.</p>
<h3 id="make-group-function"><code>MAKE-GROUP</code> (function)</h3>
<div class="codehilite"><pre><span/>(MAKE-GROUP NAME &amp;KEY TITLE HELP MANUAL OPTIONS)
</pre></div>


<h3 id="make-interface-function"><code>MAKE-INTERFACE</code> (function)</h3>
<div class="codehilite"><pre><span/>(MAKE-INTERFACE &amp;KEY NAME SUMMARY USAGE HELP MANUAL EXAMPLES CONTENTS)
</pre></div>


<h3 id="make-option-function"><code>MAKE-OPTION</code> (function)</h3>
<div class="codehilite"><pre><span/>(MAKE-OPTION NAME &amp;KEY LONG SHORT HELP MANUAL PARAMETER REDUCE (RESULT-KEY NAME)
             (INITIAL-VALUE NIL INITIAL-VALUE?) (KEY #'IDENTITY) (FINALLY #'IDENTITY))
</pre></div>


<h3 id="parse-options-function"><code>PARSE-OPTIONS</code> (function)</h3>
<div class="codehilite"><pre><span/>(PARSE-OPTIONS INTERFACE &amp;OPTIONAL (ARGUMENTS (REST (ARGV))))
</pre></div>


<p>Parse <code>arguments</code> according to <code>interface</code>.</p>
<p>Two values are returned:</p>
<ol>
<li>A fresh list of top-level, unaccounted-for arguments that don't correspond
     to any options defined in <code>interface</code>.</li>
<li>An <code>EQL</code> hash table of option keys to values.</li>
</ol>
<p>See the full documentation for more information.</p>
<h3 id="print-error-and-exit-function"><code>PRINT-ERROR-AND-EXIT</code> (function)</h3>
<div class="codehilite"><pre><span/>(PRINT-ERROR-AND-EXIT ERROR &amp;KEY (STREAM *ERROR-OUTPUT*) (EXIT-CODE 1) (PREFIX error: ))
</pre></div>


<p>Print <code>prefix</code> and <code>error</code> to <code>stream</code> and exit.</p>
<p>Example:</p>
<div class="codehilite"><pre><span/>(handler-case
    (multiple-value-bind (arguments options) (parse-options *ui*)
      (run arguments options))
  (unrecognized-option (c)
    (print-error-and-exit c)))
</pre></div>


<h3 id="print-help-function"><code>PRINT-HELP</code> (function)</h3>
<div class="codehilite"><pre><span/>(PRINT-HELP INTERFACE &amp;KEY (STREAM *STANDARD-OUTPUT*) (PROGRAM-NAME (CAR (ARGV))) (WIDTH 80)
            (OPTION-WIDTH 20) (INCLUDE-EXAMPLES T))
</pre></div>


<p>Print a pretty help document for <code>interface</code> to <code>stream</code>.</p>
<p><code>width</code> should be the total width (in characters) for line-wrapping purposes.
  Care will be taken to ensure lines are no longer than this, though some edge
  cases (extremely long short/long option names and parameters) may slip
  through.</p>
<p><code>option-width</code> should be the width of the column of short/long options (in
  characters).  If the short/long option help is shorter than this, the option's
  help string will start on the same line.  Otherwise the option's help string
  will start on the next line.</p>
<p>The result will look something like:</p>
<div class="codehilite"><pre><span/>(print-help *program-interface* :width 60 :option-width 15)
; =&gt;
; foo - do some things and meow
;
; USAGE: /bin/foo [options] FILES
;
; Foo is a program to frobulate some files, meowing as it
; happens.
;
; Options:
;   -v, --verbose    Output extra information.
;   -q, --quiet      Shut up.
;   --ignore FILE    Ignore FILE.  May be specified multiple
;                    times.
;   -n NAME, --name NAME
;                    Your name.  May be specified many times,
;                    last one wins.
;   -m, --meow       Meow.
;   0.........1.... option-width
; 0........1.........2.........3.........4.........5.........6
</pre></div>


<h3 id="print-help-and-exit-function"><code>PRINT-HELP-AND-EXIT</code> (function)</h3>
<div class="codehilite"><pre><span/>(PRINT-HELP-AND-EXIT INTERFACE &amp;KEY (STREAM *STANDARD-OUTPUT*) (PROGRAM-NAME (CAR (ARGV)))
                     (WIDTH 80) (OPTION-WIDTH 20) (INCLUDE-EXAMPLES T) (EXIT-CODE 0))
</pre></div>


<p>Print a pretty help document for <code>interface</code> to <code>stream</code> and exit.</p>
<p>Handy for easily providing --help:</p>
<div class="codehilite"><pre><span/>(multiple-value-bind (arguments options) (parse-options *ui*)
  (when (gethash 'help options)
    (print-help-and-exit *ui*))
  (run arguments options))
</pre></div>


<h3 id="print-manual-function"><code>PRINT-MANUAL</code> (function)</h3>
<div class="codehilite"><pre><span/>(PRINT-MANUAL INTERFACE &amp;KEY (STREAM *STANDARD-OUTPUT*) (MANUAL-SECTION 1))
</pre></div>


<h3 id="supply-new-value-function"><code>SUPPLY-NEW-VALUE</code> (function)</h3>
<div class="codehilite"><pre><span/>(SUPPLY-NEW-VALUE CONDITION VALUE)
</pre></div>


<p>Invoke the <code>supply-new-value</code> restart properly.</p>
<p>Example:</p>
<div class="codehilite"><pre><span/>(handler-bind
    ((unrecognized-option (alexandria:rcurry 'supply-new-value "--foo"))
  (multiple-value-bind (arguments options) (parse-options *ui*)
    (run arguments options)))
</pre></div>


<h3 id="treat-as-argument-function"><code>TREAT-AS-ARGUMENT</code> (function)</h3>
<div class="codehilite"><pre><span/>(TREAT-AS-ARGUMENT CONDITION)
</pre></div>


<p>Invoke the <code>treat-as-argument</code> restart properly.</p>
<p>Example:</p>
<div class="codehilite"><pre><span/>(handler-bind ((unrecognized-option 'treat-as-argument))
  (multiple-value-bind (arguments options) (parse-options *ui*)
    (run arguments options)))
</pre></div>


<h3 id="unrecognized-option-class"><code>UNRECOGNIZED-OPTION</code> (class)</h3>
<h4 id="slot-problematic-option">Slot <code>PROBLEMATIC-OPTION</code></h4>
<ul>
<li>Allocation: <code>:INSTANCE</code></li>
<li>Initarg: <code>:PROBLEMATIC-OPTION</code></li>
<li>Accessor: <code>PROBLEMATIC-OPTION</code></li>
</ul>
                </div>
            <footer><p><i>Made with Lisp and love by <a href="http://stevelosh.com/">Steve Losh</a>.</i></p>
<p><a href="http://rochestermade.com" title="Rochester Made"><img src="http://rochestermade.com/media/images/rochester-made-dark-on-light.png" alt="Rochester Made" title="Rochester Made"/></a></p>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-15328874-3', 'auto');
  ga('send', 'pageview');

</script></footer>
        </div>
    </body>
</html>