Results 1 to 1 of 1
Nov 27, 2013, 10:12 #1
- Join Date
- Nov 2003
- Columbus, OH
- 67 Post(s)
- 2 Thread(s)
[PHP] SimpleFlags - A more robust way to handle command line flags
I often create command line tools, and I always had trouble finding myself a good tool for handling this, so here's my attempt.
Code review and feature suggestions welcome. One feature I want to add but is hard to implement without adding more function arguments (and not sure if I want to do this yet) is type casting. I originally wrote this to accept a default value for each flag and it would attempt to auto cast the string to the type given (if default value of 3.14 is given for flag -foo, would attempt to cast that flag to a double) however its hard to ensure that a double was properly cast as opposed to a string given by accident.
EDIT: By all means try to break it. I throw an exception if a string with spaces is supplied without quote enclosure. Not sure if that is the most graceful way though.Kyle Wolfe