Command Line Lexer Kata

During some coding on a side project I found the need to create a lexer for command line args which were in the initial form of a single string and not already separated out into an array i.e. the arguments array you get in an application main method. The reason why I have called this a command line lexer and not a command line parser is that a parser usually takes an array of values and adds value by mapping the flag values and arguments to objects. Also when you use a command line parser you would normally have a set of flags and arguments which you are expecting so that you can make the assignment to the relevant object or variable. This lexer does not know what flags or arguments to expect it literally has a rule set to identify the fact that it has found a flag or an argument and return an array with these values which can then be passed onto a command line parser.

So to cut a not so long story short, it was whilst I was writing the tests for this problem I thought it was a really enjoyable and challenging exercise that it would suit a kata quite nicely. There are other katas in this area which I have seen, fewer which use a single string as the input value but with this I have drawn out a few more requirements with spaces, different quotes, multiplicity of flags, single and double dashed etc...

Initially I thought I would write this post and advise that it should be attempted without the use of regular expressions BUT I thought better of it. Instead I would say try both as it offers different challenges with or without regular expressions. That being said, my actual implementation does not use regular expressions for performance reasons but I thought I would mention it regardless. So to cut to the chase I have listed the requirements below with a description, input and an expected output.

Name: Lex one single dashed flag  
Input: "-X POST"  
Expected: ["-X","POST"]

Name: Lex a flag value which contains a space  
Input: "-H \"Content-type: application/json\" -H \"Accept: text/xml\""  
Expected: ["-H", "Content-type: application/json","-H","Accept: text/xml"]

Name: Lex a flag value which is inside single quotes  
Input: "-H 'Content-type: application/json' -H 'Accept: text/xml'"  
Expected: ["-H", "Content-type: application/json","-H","Accept: text/xml"]

Name: Lex a flag value which contains a non-flag at beginning  
Input: " A -H \"Content-type: application/json\""  
Expected: ["A", "-H", "Content-type: application/json"]

Name: Lex a flag value with double quotes inside single quotes",func(){  
Input: "-d '{\"name\":\"bob\"}'"  
Expected: ["-d", "{\"name\":\"bob\"}"]

Name: Lex a flag value with single quotes inside double quotes",func(){  
Input: "-d \"{'name':'bob'}\""  
Expected: ["-d", "{'name':'bob'}"]

Name: Lex a double dashed flag  
Input: "--cert ca.pem"  
Expected: ["--cert","ca.pem"]

Name: Lex a double dashed flag without value  
Input: "--dummy --cert ca.pem"  
Expected: ["--dummy","--cert","ca.pem"]

Name: Lex extra spaces between flags  
Input: "       --dummy     --cert     ca.pem    -X     POST    "  
Expected: ["--dummy","--cert","ca.pem","-X","POST"]

Name: Lex commands amongst flags  
Input: "--dummy command --cert ca.pem"  
Expected: ["--dummy","command","--cert","ca.pem"]

Name: Lex flags with a colon separator between flag and value  
Input: "-X:POST --cert:ca.pem"  
Expected: ["-X","POST","--cert","ca.pem"]