Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enum option #4

Closed
houyunf opened this issue Dec 30, 2011 · 2 comments
Closed

enum option #4

houyunf opened this issue Dec 30, 2011 · 2 comments
Assignees

Comments

@houyunf
Copy link

houyunf commented Dec 30, 2011

It will be very helpful to provide enum option support and should not be hard to implement.

@lexicalscope
Copy link
Owner

Can you possibly elaborate on this please? I was under the impression
that enum options are already supported. Are they not working?

@lexicalscope
Copy link
Owner

I believe that enum options should work and hopefully have been available for some time. Here is an example of how to use them (NB. in this example both options are optional, but it will work just as well for mandatory options):

    public class TestEnumOptionExample {
        public enum ExampleEnum {
            Value1, Value2, Value3
        }

        interface EnumOptionExample
        {
            @Option 
            ExampleEnum getOptionOne();
            boolean isOptionOne();

            @Option 
            List<ExampleEnum> getOptionTwo();
            boolean isOptionTwo();
        }

        @Test public void specifiedSingleValueEnumOptionGivesEnumValue() {
            final EnumOptionExample cli =
                CliFactory.parseArguments(EnumOptionExample.class, "--optionOne", "Value2");

            assertThat(cli.getOptionOne(), equalTo(ExampleEnum.Value2));
        }

        @Test public void specifiedMultivaluedEnumOptionGivesListOfEnumValues() {
            final EnumOptionExample cli =
                CliFactory.parseArguments(EnumOptionExample.class, "--optionTwo", "Value1", "Value3");

            assertThat(cli.getOptionTwo(), hasItems(ExampleEnum.Value1, ExampleEnum.Value3));
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants