<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Types</title><link>https://sourceforge.net/p/argument/wiki/Types/</link><description>Recent changes to Types</description><atom:link href="https://sourceforge.net/p/argument/wiki/Types/feed" rel="self"/><language>en</language><lastBuildDate>Thu, 05 Dec 2013 02:37:52 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/argument/wiki/Types/feed" rel="self" type="application/rss+xml"/><item><title>Types modified by Chris DeGreef</title><link>https://sourceforge.net/p/argument/wiki/Types/</link><description>&lt;div class="markdown_content"&gt;&lt;p&gt;This is a required part of the argument definition.  It determines the type of data the user will be able to enter as a value for the argument.  Other parts of the definition will allow for fine-tuning of the type, like constraints and formats.  Each of the examples will also assign the &lt;code&gt;--key&lt;/code&gt; parameter so that they make sense; &lt;code&gt;--key&lt;/code&gt; is a required part of specifying an argument.&lt;br /&gt;
&lt;/p&gt;
&lt;p&gt;The examples are made up of the Java set up for the parser and then a command-line example of using a program (&lt;code&gt;MyProgram&lt;/code&gt;) with that argument.&lt;/p&gt;
&lt;h2&gt;boolean&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;Booleans&lt;/code&gt; have no value associated with them.  If the user indicates a boolean argument then the value is true.  Otherwise, if not specified at all, the boolean will be false.  &lt;em&gt;(This can be changed with the "default" parameter.)&lt;/em&gt;&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type boolean --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;string&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;String&lt;/code&gt; lets the user enter anything as the value.  It will be interpreted as an formless list of characters.  If spaces or special, reserved characters are needed for the value then the value must be enclosed in quotes.&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type string --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d "Hello World"&lt;/pre&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;MyProgram -d NothingSpecialHere&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;integer&lt;/h2&gt;
&lt;p&gt;An &lt;code&gt;integer&lt;/code&gt; argument expects the user to enter a whole number.  It can be negative, but the negative sign (a dash) is a special character.  So negative numbers must be quoted. &lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type integer --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d 123&lt;/pre&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;MyProgram -d "-456"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;long&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;long&lt;/code&gt; argument expects the user to enter a whole number.  It can be negative, but the negative sign (a dash) is a special character.  So negative numbers must be quoted.  Notice that the sign of the number can be at the beginning or at the end of the number.  This is very much like an integer but allows for much larger numbers to be entered.  long and integer have more significance when dealing with the &lt;code&gt;--var&lt;/code&gt; parameter.&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type long --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d 123456&lt;/pre&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;MyProgram -d "123456-"&lt;br /&gt;
MyProgram -d "-123456"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;byte&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;byte&lt;/code&gt; argument expects the user to enter a small whole number; something between 0 and 255.  It can not be negative.  There are three ways to enter the value; as a single, printable character, an integer between 0 and 255, or as a special symbol representing a special control character like a line feed (LF).&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type byte --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d z&lt;/pre&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;MyProgram -d 87&lt;br /&gt;
MyProgram -d LF&lt;br /&gt;
This is a list of all of the special symbols and their decimal equivalents.&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;NULL(0) SOH(1) STX(2) ETX(3) EOT(4) ENQ(5) ACK(6) BEL(7) BS(8)&lt;br /&gt;
HT(9) LF(10) VT(11) FF(12) CR(13) SO(14) SI(15) DLE(16)&lt;br /&gt;
DC1(17) DC2(18) DC3(19) DC4(20) NAK(21) SYN(22) ETB(23) CAN(24)&lt;br /&gt;
EM(25) SUB(26) ESC(27) FS(28) GS(29) RS(30) US(31) SP(32)&lt;/pre&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;float&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;float&lt;/code&gt; argument expects the user to enter a floating point number.  It can be negative, but the negative sign (a dash) is a special character.  So negative numbers must be quoted. &lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type float --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d 123.005&lt;/pre&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;MyProgram -d "-0.123"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;double&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;double&lt;/code&gt; argument expects the user to enter a potentially very large floating point number.  It can be negative, but the negative sign (a dash) is a special character.  So negative numbers must be quoted.  This is very much like a float but allows for much larger numbers to be entered.  float and double have more significance when dealing with the &lt;code&gt;--var&lt;/code&gt; parameter.&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type double --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d 1.23456&lt;/pre&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;MyProgram -d "12345.6-"&lt;br /&gt;
MyProgram -d "-123.456"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;date&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;date&lt;/code&gt; argument expects the user to enter a date that may include a timestamp as well.  If any special characters, including a space, are to be used in the date / time then the value must be quoted.   See the discussion on &lt;code&gt;--format&lt;/code&gt; for details on controlling the date / time format the user can use to type in a date.  The assumption in this example is that the format will be month, day, and year only.&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type date --key d --format MMddyy");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d 040960&lt;/pre&gt;&lt;br /&gt;
That example would set the date to be April, 9th 1960.  Dates roll forward.  So if you enter 45 as the day part of the date then it will add one to the month and set the day to be around 15 days into that month.&lt;/p&gt;
&lt;h2&gt;enum&lt;/h2&gt;
&lt;p&gt;An &lt;code&gt;enum&lt;/code&gt; lets the user enter a value that must be a member of a specific &lt;code&gt;enum &lt;/code&gt;class.  There can be no spaces or special characters in an &lt;code&gt;enum &lt;/code&gt;so quotes are not necessarily needed for any value, but they could be used if so desired.  An &lt;code&gt;enum &lt;/code&gt;requires a Java &lt;code&gt;enum &lt;/code&gt;class to be associated with the argument.  Please see the documentation on &lt;em&gt;variable assignments&lt;/em&gt; for more specifics.  In this example it is assumed that a variable in your class (&lt;code&gt;logLevel&lt;/code&gt;) is of a type of &lt;code&gt;LogLevel&lt;/code&gt;, an implementation of &lt;code&gt;enum&lt;/code&gt;.  &lt;code&gt;logLevel&lt;/code&gt; will be set to the corresponding &lt;code&gt;enum &lt;/code&gt;value according to what the user enters as the value.  An incorrect value will produce an error for the user.&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type enum --key d --var logLevel");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d WARN&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;file&lt;/h2&gt;
&lt;p&gt;A file argument expects the name of a file, perhaps even a path (or only a path), to be entered as a value.  Argument will create a File instance with the name set up to be the provided value. &lt;br /&gt;
It is almost always a good idea to quote the file names just be make sure any spaces or special characters do not cause problems.&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type file --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d c:/tmp/myFile.txt&lt;/pre&gt;&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;MyProgram -d "c:/program files/myFile.txt"&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2&gt;pattern&lt;/h2&gt;
&lt;p&gt;A &lt;code&gt;pattern&lt;/code&gt; argument allows the user to enter a &lt;code&gt;Pattern&lt;/code&gt; as a value.  It is a good idea to always quote the value coming in since patterns most often contain special characters and spaces.  Argument will create a compiled instance of a &lt;code&gt;Java Pattern&lt;/code&gt;.  It can then be used to &lt;code&gt;match &lt;/code&gt;other &lt;code&gt;Strings&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This can be used for something like a database query where &lt;code&gt;MyProgram &lt;/code&gt;takes the supplied pattern and uses it to select records that in this case have "&lt;em&gt;Joe&lt;/em&gt;" as the beginning part of a column in the database.&lt;br /&gt;
&lt;pre class="java:html:nocontrols" name="code"&gt;CmdLine.create("--type pattern --key d");&lt;/pre&gt;&lt;br /&gt;
&lt;pre class="html:nocontrols:nogutter" name="code"&gt;&amp;gt; MyProgram -d "Joe.*"&lt;/pre&gt;&lt;/p&gt;&lt;/div&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Chris DeGreef</dc:creator><pubDate>Thu, 05 Dec 2013 02:37:52 -0000</pubDate><guid>https://sourceforge.net82421a2f6c166a594e5f38ac9f1b8c9643888d53</guid></item></channel></rss>