Commons CLI getValue() and getOptionValue()
<p>I'm a bit puzzled about the two methods. When I use <code>getOptionValue(optionName)</code> I do get the argument that I had entered in the command line but I get null when I use <code>optionName.getValue()</code></p>

<p>getValue()</p>

<blockquote>
  <p>Returns the specified value of this Option or null if there is no
  value.</p>
</blockquote>

<p>getOptionValue(String)</p>

<blockquote>
  <p>Retrieve the first argument, if any, of this option.</p>
</blockquote>

<p>As you can see <code>getOptionValue(String)</code> explicitly says argument where as the other only says value but they both have "value" in their method name. Since there is no <code>setValue(String)</code> method or something of such, I just assumed it's just the same as argument.</p>

<pre><code>public static void main(final String[] args ) {
    CommandLine cmd = null;
    Option program = Option.builder("p")
             .hasArg()
             .required(true)
             .longOpt("program")
             .build();

    Options options = new Options();
    options.addOption( program );

    CommandLineParser parser = new DefaultParser();
    try {
        cmd = parser.parse( options, args );
    }
    catch( ParseException exp ) {
        System.err.println( "Parsing failed.  Reason: " + exp.getMessage() );
    }

    String[] list;
    list = cmd.getArgs();

    int argsN = program.getArgs();
    String optionValue = cmd.getOptionValue("p");
    String value = program.getValue();

    System.out.println(argsN);
    System.out.println(optionValue);
    System.out.println(value);

}
</code></pre>

<p>Output is:</p>

<p>1</p>

<p>[arg]</p>

<p>null</p>