arg_parser icon indicating copy to clipboard operation
arg_parser copied to clipboard

Array type

Open kostya opened this issue 2 years ago • 4 comments

would be nice to have default array parser like this:

struct MyArgs
  include ArgParser
  getter ids : Array(Int32)
end

args = MyArgs.new(["--ids", "1,2,3"])

kostya avatar Jan 28 '23 19:01 kostya

Array's could be parsed a number of different ways, so I have a converter for that. Check out the CommaSeparatedArrayConverter.

watzon avatar Jan 28 '23 21:01 watzon

You can also look here for a usage example

watzon avatar Jan 28 '23 21:01 watzon

why not add it by default, to less typing.

kostya avatar Jan 28 '23 21:01 kostya

I decided since an Array isn't a primitive in the same way int, float, string, and boolean are it made more sense to not give just one way to do it. This way they can use the provided converter if they want to format their arrays as comma separated values, or they can provide their own converter for a custom format.

Multiple of the same argument can also be used for Arrays, which is kind of the default. So: -arg "hello" -arg "world" would add both hello and world to the array (assuming it is an array type)

watzon avatar Jan 28 '23 23:01 watzon