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

Support for Enum Flags? #19

Closed
halwaxt opened this issue Jun 8, 2012 · 5 comments
Closed

Support for Enum Flags? #19

halwaxt opened this issue Jun 8, 2012 · 5 comments

Comments

@halwaxt
Copy link

halwaxt commented Jun 8, 2012

First I want to thank you for your great work!

Is there a way to provide enum parameters which are defined as flags and or'ed together?

[Flags]
enum FileType {
    Csv,
    Excel
}

[Verb]
void CreateFiles([Parameter] FileType fileType) { ... }

How to call the method with Csv and Excel enabled?

MySuperApp createfiles -filetype=Csv|Excel

Thanks in advance
Thomas

@adrianaisemberg
Copy link
Owner

Interesting!
Currently you'll have to parse it by yourself but it's a great feature.
I'll implement.

Thanks,
Adrian

[mobile]
From: halwaxt
Sent: 6/8/2012 1:52 PM
To: Adrian Aisemberg
Subject: [CLAP] Support for Enum Flags? (#19)
First I want to thank you for your great work!

Is there a way to provide enum parameters which are defined as flags
and or'ed together?

[Flags]
enum FileType {
    Csv,
    Excel
}

[Verb]
void CreateFiles([Parameter] FileType fileType) { ... }

How to call the method with Csv and Excel enabled?

MySuperApp createfiles -filetype=Csv|Excel

Thanks in advance
Thomas


Reply to this email directly or view it on GitHub:
#19

@adrianaisemberg
Copy link
Owner

Apparently, flag enums are already supported using a comma:
MySuperApp createfiles -filetype=Csv,Excel

That's how Enum.Parse works, which is used by CLAP.

Cheers!

@adrianaisemberg
Copy link
Owner

Don't forget to set a proper flag value to each enum value:

[Flags]
enum FileType
{
Csv = 1,
Excel = 2,
...4, 8, 16 ...
}

otherwise, the compiler will set the default values, which are 0,1,2,3,... which are not real flags.

@halwaxt
Copy link
Author

halwaxt commented Jun 9, 2012

Thanks for your help Adrian, I'll implement your suggestions as soon as possible!

Thomas

@halwaxt
Copy link
Author

halwaxt commented Jun 12, 2012

Adrian,

works like a charm :-) Thanks a lot!

Thomas

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

No branches or pull requests

2 participants