You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Joe Casadonte (JIRA)" <ji...@apache.org> on 2011/06/02 18:29:47 UTC

[jira] [Created] (CLI-220) MissingOptionException.getMissingOptions() returns OptionGroup, not just String

MissingOptionException.getMissingOptions() returns OptionGroup, not just String
-------------------------------------------------------------------------------

                 Key: CLI-220
                 URL: https://issues.apache.org/jira/browse/CLI-220
             Project: Commons CLI
          Issue Type: Bug
          Components: CLI-1.x
    Affects Versions: 1.2
            Reporter: Joe Casadonte


The following code:

{code:title=Test.java|borderStyle=solid}
import java.util.List;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.MissingOptionException;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.OptionGroup;
import org.apache.commons.cli.Options;

public class Test {
	public static void main(String[] argv)
	{
		Option opt_foo =
			OptionBuilder.hasArg(false)
				.isRequired(true)
				.withDescription("option foo")
		        .create("foo");

		Option opt_bar =
			OptionBuilder.hasArg(false)
				.isRequired(false)
				.withDescription("option bar")
		        .create("bar");

		Option opt_baz =
			OptionBuilder.hasArg(false)
				.isRequired(false)
				.withDescription("option baz")
		        .create("baz");

		OptionGroup optgrp = new OptionGroup();
		optgrp.setRequired(true);
		optgrp.addOption(opt_bar)
			.addOption(opt_baz);

		Options optsdef = new Options();
		optsdef.addOption(opt_foo)
			.addOptionGroup(optgrp);

		try {
			CommandLineParser parser = new GnuParser();
			CommandLine cmdline = parser.parse(optsdef, argv);
		}
		catch (MissingOptionException ex) {
			List opts = ex.getMissingOptions();

			for (Object option : opts) {
				System.out.println("OPT: " + option.getClass().getName());
			}
		}
		catch (Exception ex) {
			ex.printStackTrace();
			System.exit(1);
		}
	}
}
{code}

produces the following output:

{code}
</tmp/MissingOptionException> $ javac -cp commons-cli-1.2.jar Test.java

</tmp/MissingOptionException> $ java -cp commons-cli-1.2.jar:. Test
OPT: java.lang.String
OPT: org.apache.commons.cli.OptionGroup
{code}

The JavaDoc for MissingOptionException.getMissingOptions() says:

{quote}
Return the list of options (as strings) missing in the command line parsed.
{quote}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CLI-220) MissingOptionException.getMissingOptions() returns OptionGroup, not just String

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044965#comment-13044965 ] 

Emmanuel Bourg commented on CLI-220:
------------------------------------

I agree it's not really nice to have a list of mixed types, but that's how it was done and it can't be changed without breaking the backward compatibility.

What we can do is to add helper methods in the exception to simplify the processing, but what kind of string would you expect for a missing group of options?

> MissingOptionException.getMissingOptions() returns OptionGroup, not just String
> -------------------------------------------------------------------------------
>
>                 Key: CLI-220
>                 URL: https://issues.apache.org/jira/browse/CLI-220
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x, Documentation
>    Affects Versions: 1.2
>            Reporter: Joe Casadonte
>            Priority: Minor
>             Fix For: 1.3
>
>
> The following code:
> {code:title=Test.java|borderStyle=solid}
> import java.util.List;
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.CommandLineParser;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.MissingOptionException;
> import org.apache.commons.cli.Option;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.OptionGroup;
> import org.apache.commons.cli.Options;
> public class Test {
> 	public static void main(String[] argv)
> 	{
> 		Option opt_foo =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(true)
> 				.withDescription("option foo")
> 		        .create("foo");
> 		Option opt_bar =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option bar")
> 		        .create("bar");
> 		Option opt_baz =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option baz")
> 		        .create("baz");
> 		OptionGroup optgrp = new OptionGroup();
> 		optgrp.setRequired(true);
> 		optgrp.addOption(opt_bar)
> 			.addOption(opt_baz);
> 		Options optsdef = new Options();
> 		optsdef.addOption(opt_foo)
> 			.addOptionGroup(optgrp);
> 		try {
> 			CommandLineParser parser = new GnuParser();
> 			CommandLine cmdline = parser.parse(optsdef, argv);
> 		}
> 		catch (MissingOptionException ex) {
> 			List opts = ex.getMissingOptions();
> 			for (Object option : opts) {
> 				System.out.println("OPT: " + option.getClass().getName());
> 			}
> 		}
> 		catch (Exception ex) {
> 			ex.printStackTrace();
> 			System.exit(1);
> 		}
> 	}
> }
> {code}
> produces the following output:
> {code}
> </tmp/MissingOptionException> $ javac -cp commons-cli-1.2.jar Test.java
> </tmp/MissingOptionException> $ java -cp commons-cli-1.2.jar:. Test
> OPT: java.lang.String
> OPT: org.apache.commons.cli.OptionGroup
> {code}
> The JavaDoc for MissingOptionException.getMissingOptions() says:
> {quote}
> Return the list of options (as strings) missing in the command line parsed.
> {quote}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Updated] (CLI-220) MissingOptionException.getMissingOptions() returns OptionGroup, not just String

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-220?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated CLI-220:
-------------------------------

      Component/s: Documentation
         Priority: Minor  (was: Major)
    Fix Version/s: 1.3

Thank you for the detailed report Joe. The javadoc should be updated to reflect this.

> MissingOptionException.getMissingOptions() returns OptionGroup, not just String
> -------------------------------------------------------------------------------
>
>                 Key: CLI-220
>                 URL: https://issues.apache.org/jira/browse/CLI-220
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x, Documentation
>    Affects Versions: 1.2
>            Reporter: Joe Casadonte
>            Priority: Minor
>             Fix For: 1.3
>
>
> The following code:
> {code:title=Test.java|borderStyle=solid}
> import java.util.List;
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.CommandLineParser;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.MissingOptionException;
> import org.apache.commons.cli.Option;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.OptionGroup;
> import org.apache.commons.cli.Options;
> public class Test {
> 	public static void main(String[] argv)
> 	{
> 		Option opt_foo =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(true)
> 				.withDescription("option foo")
> 		        .create("foo");
> 		Option opt_bar =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option bar")
> 		        .create("bar");
> 		Option opt_baz =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option baz")
> 		        .create("baz");
> 		OptionGroup optgrp = new OptionGroup();
> 		optgrp.setRequired(true);
> 		optgrp.addOption(opt_bar)
> 			.addOption(opt_baz);
> 		Options optsdef = new Options();
> 		optsdef.addOption(opt_foo)
> 			.addOptionGroup(optgrp);
> 		try {
> 			CommandLineParser parser = new GnuParser();
> 			CommandLine cmdline = parser.parse(optsdef, argv);
> 		}
> 		catch (MissingOptionException ex) {
> 			List opts = ex.getMissingOptions();
> 			for (Object option : opts) {
> 				System.out.println("OPT: " + option.getClass().getName());
> 			}
> 		}
> 		catch (Exception ex) {
> 			ex.printStackTrace();
> 			System.exit(1);
> 		}
> 	}
> }
> {code}
> produces the following output:
> {code}
> </tmp/MissingOptionException> $ javac -cp commons-cli-1.2.jar Test.java
> </tmp/MissingOptionException> $ java -cp commons-cli-1.2.jar:. Test
> OPT: java.lang.String
> OPT: org.apache.commons.cli.OptionGroup
> {code}
> The JavaDoc for MissingOptionException.getMissingOptions() says:
> {quote}
> Return the list of options (as strings) missing in the command line parsed.
> {quote}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Commented] (CLI-220) MissingOptionException.getMissingOptions() returns OptionGroup, not just String

Posted by "Joe Casadonte (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-220?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044836#comment-13044836 ] 

Joe Casadonte commented on CLI-220:
-----------------------------------

Hi Emmanuel,

I'm curious why you're considering this a documentation bug and not a code bug?  The amount of code I have to write to deal with the possibility that I'm not getting a String back is not a lot, but it *is* a PITA.  I would think the method should return all Strings or all Objects, but not a mix of the two.  Just my thoughts -- thank you for all of the work you and others do maintaining this code!


joe

> MissingOptionException.getMissingOptions() returns OptionGroup, not just String
> -------------------------------------------------------------------------------
>
>                 Key: CLI-220
>                 URL: https://issues.apache.org/jira/browse/CLI-220
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x, Documentation
>    Affects Versions: 1.2
>            Reporter: Joe Casadonte
>            Priority: Minor
>             Fix For: 1.3
>
>
> The following code:
> {code:title=Test.java|borderStyle=solid}
> import java.util.List;
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.CommandLineParser;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.MissingOptionException;
> import org.apache.commons.cli.Option;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.OptionGroup;
> import org.apache.commons.cli.Options;
> public class Test {
> 	public static void main(String[] argv)
> 	{
> 		Option opt_foo =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(true)
> 				.withDescription("option foo")
> 		        .create("foo");
> 		Option opt_bar =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option bar")
> 		        .create("bar");
> 		Option opt_baz =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option baz")
> 		        .create("baz");
> 		OptionGroup optgrp = new OptionGroup();
> 		optgrp.setRequired(true);
> 		optgrp.addOption(opt_bar)
> 			.addOption(opt_baz);
> 		Options optsdef = new Options();
> 		optsdef.addOption(opt_foo)
> 			.addOptionGroup(optgrp);
> 		try {
> 			CommandLineParser parser = new GnuParser();
> 			CommandLine cmdline = parser.parse(optsdef, argv);
> 		}
> 		catch (MissingOptionException ex) {
> 			List opts = ex.getMissingOptions();
> 			for (Object option : opts) {
> 				System.out.println("OPT: " + option.getClass().getName());
> 			}
> 		}
> 		catch (Exception ex) {
> 			ex.printStackTrace();
> 			System.exit(1);
> 		}
> 	}
> }
> {code}
> produces the following output:
> {code}
> </tmp/MissingOptionException> $ javac -cp commons-cli-1.2.jar Test.java
> </tmp/MissingOptionException> $ java -cp commons-cli-1.2.jar:. Test
> OPT: java.lang.String
> OPT: org.apache.commons.cli.OptionGroup
> {code}
> The JavaDoc for MissingOptionException.getMissingOptions() says:
> {quote}
> Return the list of options (as strings) missing in the command line parsed.
> {quote}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

[jira] [Resolved] (CLI-220) MissingOptionException.getMissingOptions() returns OptionGroup, not just String

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-220?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg resolved CLI-220.
--------------------------------

    Resolution: Fixed

> MissingOptionException.getMissingOptions() returns OptionGroup, not just String
> -------------------------------------------------------------------------------
>
>                 Key: CLI-220
>                 URL: https://issues.apache.org/jira/browse/CLI-220
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-1.x, Documentation
>    Affects Versions: 1.2
>            Reporter: Joe Casadonte
>            Priority: Minor
>             Fix For: 1.3
>
>
> The following code:
> {code:title=Test.java|borderStyle=solid}
> import java.util.List;
> import org.apache.commons.cli.CommandLine;
> import org.apache.commons.cli.CommandLineParser;
> import org.apache.commons.cli.GnuParser;
> import org.apache.commons.cli.MissingOptionException;
> import org.apache.commons.cli.Option;
> import org.apache.commons.cli.OptionBuilder;
> import org.apache.commons.cli.OptionGroup;
> import org.apache.commons.cli.Options;
> public class Test {
> 	public static void main(String[] argv)
> 	{
> 		Option opt_foo =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(true)
> 				.withDescription("option foo")
> 		        .create("foo");
> 		Option opt_bar =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option bar")
> 		        .create("bar");
> 		Option opt_baz =
> 			OptionBuilder.hasArg(false)
> 				.isRequired(false)
> 				.withDescription("option baz")
> 		        .create("baz");
> 		OptionGroup optgrp = new OptionGroup();
> 		optgrp.setRequired(true);
> 		optgrp.addOption(opt_bar)
> 			.addOption(opt_baz);
> 		Options optsdef = new Options();
> 		optsdef.addOption(opt_foo)
> 			.addOptionGroup(optgrp);
> 		try {
> 			CommandLineParser parser = new GnuParser();
> 			CommandLine cmdline = parser.parse(optsdef, argv);
> 		}
> 		catch (MissingOptionException ex) {
> 			List opts = ex.getMissingOptions();
> 			for (Object option : opts) {
> 				System.out.println("OPT: " + option.getClass().getName());
> 			}
> 		}
> 		catch (Exception ex) {
> 			ex.printStackTrace();
> 			System.exit(1);
> 		}
> 	}
> }
> {code}
> produces the following output:
> {code}
> </tmp/MissingOptionException> $ javac -cp commons-cli-1.2.jar Test.java
> </tmp/MissingOptionException> $ java -cp commons-cli-1.2.jar:. Test
> OPT: java.lang.String
> OPT: org.apache.commons.cli.OptionGroup
> {code}
> The JavaDoc for MissingOptionException.getMissingOptions() says:
> {quote}
> Return the list of options (as strings) missing in the command line parsed.
> {quote}

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira