You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Jürgen Weber <we...@hotmail.com> on 2002/11/27 14:23:56 UTC

CLI: ParseException:Unrecognized option: -p

Hello,

if I try the test below there is a ParseException I cannot explain. Is my 
code wrong or is there a bug in CLI (1.0) ?

Thanks,
Juergen

java version "1.4.1_01"


C:\lib>java -classpath  .;commons-cli-1.0.jar  CliTest
Commandline ParseException:Unrecognized option: -p

------------------------- CliTest.java ------------
import org.apache.commons.cli.*;

public class CliTest
{

	public static void main(String[] args)
	{
		String[] argus={

		"-pkg","package","-td","../gen","Method.dtd"

		};

		parseCommandline(argus);
	}


	private static void parseCommandline(String[] args)
	{
		String s=null;

		Options tOptions = new Options();

		tOptions.addOption("i", true, "input data folder");
		tOptions.addOption("td", true, "output folder");
		tOptions.addOption("pkg", true, "package");

		CommandLineParser parser = new PosixParser();

		try
		{
			CommandLine line = parser.parse(tOptions, args);
		}
		catch (ParseException exp)
		{
			System.out.println("Commandline ParseException:" + exp.getMessage());
		}

	}
}





_________________________________________________________________
Messenger  -  Wer in Echtzeit kommunizieren will, lädt den MSN Messenger. 
Cool, kostenlos und mit 3D Emoticons: http://messenger.msn.de


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: CLI: ParseException:Unrecognized option: -p

Posted by John Keyes <jb...@mac.com>.
Hi Jürgen,

The option you create here:
> 		tOptions.addOption("pkg", true, "package");
states that the shortOpt value for this option is 'pkg'.
Any shortOpt that is created with a value whose lenght is
greater than one should be parsed using the GnuParser.

So if you replace:
> 		CommandLineParser parser = new PosixParser();
with:
    CommandLineParser parser = new GnuParser();
then things should behave as you would like.

Cheers,
-John K

p.s. small point of note, this is really a commons-user mail,
it just makes it easier for some peoples filters.  The other
thing is that when you send a mail to commons-xxx you should
begin your mail with [sub-project] e.g. [cli], again this
helps peoples filters.

On Wed, 2002-11-27 at 13:23, Jürgen Weber wrote:
> Hello,
> 
> if I try the test below there is a ParseException I cannot explain. Is my 
> code wrong or is there a bug in CLI (1.0) ?
> 
> Thanks,
> Juergen
> 
> java version "1.4.1_01"
> 
> 
> C:\lib>java -classpath  .;commons-cli-1.0.jar  CliTest
> Commandline ParseException:Unrecognized option: -p
> 
> ------------------------- CliTest.java ------------
> import org.apache.commons.cli.*;
> 
> public class CliTest
> {
> 
> 	public static void main(String[] args)
> 	{
> 		String[] argus={
> 
> 		"-pkg","package","-td","../gen","Method.dtd"
> 
> 		};
> 
> 		parseCommandline(argus);
> 	}
> 
> 
> 	private static void parseCommandline(String[] args)
> 	{
> 		String s=null;
> 
> 		Options tOptions = new Options();
> 
> 		tOptions.addOption("i", true, "input data folder");
> 		tOptions.addOption("td", true, "output folder");
> 		tOptions.addOption("pkg", true, "package");
> 
> 		CommandLineParser parser = new PosixParser();
> 
> 		try
> 		{
> 			CommandLine line = parser.parse(tOptions, args);
> 		}
> 		catch (ParseException exp)
> 		{
> 			System.out.println("Commandline ParseException:" + exp.getMessage());
> 		}
> 
> 	}
> }
> 
> 
> 
> 
> 
> _________________________________________________________________
> Messenger  -  Wer in Echtzeit kommunizieren will, lädt den MSN Messenger. 
> Cool, kostenlos und mit 3D Emoticons: http://messenger.msn.de
> 
> 
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
-- 
John Keyes <jb...@mac.com>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>