Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here is an example of using its <code>with-command-line</code> macro. The following code specifies a trivial class with a main method that does nothing but print out the values of its command line arguments.</p> <pre><code>(ns cmd-line-demo (:gen-class) (:use clojure.contrib.command-line)) (defn -main [&amp; args] (with-command-line args "Command line demo" [[foo "This is the description for foo" 1] [bar "This is the description for bar" 2] [boolean? b? "This is a boolean flag."] remaining] (println "foo: " foo) (println "bar: " bar) (println "boolean?: " boolean?) (println "remaining: " remaining))) </code></pre> <p>Compile the class at the REPL:</p> <pre><code>user&gt; (compile 'cmd-line-demo) cmd-line-demo </code></pre> <h2>Example usage</h2> <p>1) Executing with no command line arguments will cause the help info to be displayed. The help info can also be displayed with <code>--help</code> or <code>-h</code> flags. Note that the help info is automatically generated from your cmdspec.</p> <pre><code>$ java -classpath . cmd_line_demo Command line demo Options --foo &lt;arg&gt; This is the description for foo [default 1] --bar &lt;arg&gt; This is the description for bar [default 2] --boolean, -b This is a boolean flag. </code></pre> <p>2) Unspecified arguments receive the default value as specified in the cmdspec binding. For example, <code>bar</code> has a default value of <code>2</code>.</p> <pre><code>$ java -classpath . cmd_line_demo --foo "changed value" foo: changed value bar: 2 boolean?: nil remaining: [] </code></pre> <p>3) Boolean flags are denoted by the suffix "?" in the cmdspec. Note that the flag itself does <strong>not</strong> include the "?" as part of its name.</p> <pre><code>$ java -classpath . cmd_line_demo -boolean foo: 1 bar: 2 boolean?: true remaining: [] </code></pre> <p>4) Also note that you may specify flag aliases by specifying multiple symbols in the cmdspec. I have done this with the <code>boolean?</code> and <code>b?</code> flags.</p> <p>5) Finally, I've specified that <code>remaining</code> capture all remaining arguments without associated flags.</p> <pre><code>$ java -classpath . cmd_line_demo -foo test file1 file2 file3 foo: test bar: 2 boolean?: nil remaining: [file1 file2 file3] </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload