how to use OptionList...

Nov 5, 2009 at 4:05 PM

Hello I am having trouble getting OptionList to work.

 

I want the following

-mbg xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx

this is what i have on my type:

 

[ValueList(typeof(List<string>))]
            [OptionList("mbg","mbg",Separator=',')]
            public IList<string> Gateways = null;

[OptionList("mbg","mbg",Separator=',')]

public IList<string> Gateways = null;

 

Any thoughts?

 

Coordinator
Nov 6, 2009 at 3:43 PM

Dear user,

you're having problems for two reason:

  1. you are using the same name for short and long option (and this may be a little confusing...)
  2. in your invocation example you use a single dash (again, single dash are for short option or for short options group [*1]) and you leave a space after separator (,) character

Without changing the code the correct command line invocation is:

yourapp --mbg xxx.xxx.xxx.xxx,xxx.xxx.xxx.xxx

(If you enclose the value between quotes still using the space - like this "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx" - the second item will start with a space ' '.)

I could suggest you two solutions.

A) Don't the define the short option name:

[OptionList(null, "mbg", Separator = ',')]

in this way your app will accept the input suggested above.

B) Define a correct (again, read [*1]) short option of only 1 character (you could also suggest in your help screen to enclose the argument in double quotes):

[OptionList("m", "mbg", Separator = ',')]

doing in this way and calling String.Trim() for each element of IList<string> you could allow an input like this

yourapp -m "xxx.xxx.xxx.xxx, xxx.xxx.xxx.xxx"

that is more similar to what you intended to get.

--------------------------------------------------

[*1] Actually short option name with more than more character are allowed, but as you can see, this can be cause of problems. The next version will solve this issue. For now use short options of one character or set the property to null.

--------------------------------------------------

Regards,

 Giacomo

Coordinator
Nov 15, 2009 at 11:10 AM

Dear user,

version 1.6.0.77 beta (or higher, available in source code control repository)

http://commandline.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=35668

forces to define short name to null or to a one character string.

Thank again,

Giacomo

P.S.: If anyone thinks that things should work differently, please post a reply or open an issue on issue tracker.

Coordinator
Nov 28, 2009 at 11:28 AM

Dear user (and everyone interested),

please consider the use of OptionArray[Attribute]. This feature (still not present in a version marked stable or rc) is available from version branch 1.7+ (at the moment the more stable is 1.7.10.5 beta).

Please read: http://commandline.codeplex.com/wikipage?title=The-Option-Array-Attribute&referringTitle=Documentation.

More on OptionList[Attribute]: http://commandline.codeplex.com/wikipage?title=The-Option-List-Attribute&referringTitle=Documentation.

Regards,

Giacomo