I need to parse lines intended for cross-spawn
From the following lines:
cmd foo bar
cmd "foo bar" --baz boom
cmd "baz \"boo\" bam"
cmd "foo 'bar bud' jim" jam
FOO=bar cmd baz
To the object:
{command: 'cmd', args: ['foo', 'bar']}
{command: 'cmd', args: ['foo bar', '--baz', 'boom']}
{command: 'cmd', args: ['baz "boo" bam']}
{command: 'cmd', args: ['foo \'bar bud\' jim', 'jam']}
{command: 'cmd', args: ['baz'], env: {FOO: 'bar'}}
I think regex will be possible, but I would like to avoid writing something ordinary. Does anyone know anything existing that can do this?
Edit
The question and answers are still valuable, but for my specific use case I no longer need to do this. Instead, I use spawn-command(more precisely, I will use spawn-command-with-kill), which does not require separation commandand args. It will make life a lot easier for me. Thank!
source
share