Skip to content

Instantly share code, notes, and snippets.

@zeddash
Last active May 20, 2020 15:57
Show Gist options
  • Select an option

  • Save zeddash/842ef7d76a9e6ad0a0c4c1c012ea6752 to your computer and use it in GitHub Desktop.

Select an option

Save zeddash/842ef7d76a9e6ad0a0c4c1c012ea6752 to your computer and use it in GitHub Desktop.
Command Parser
{
"scripts": [],
"styles": []
}
const commands = [
"--command",
"--command value",
"-- command --option",
"-- command --no-option",
"-- command value --option",
"-dcommand value --option 5 -v",
"dolphin command value --option true -v yes"
]
const commandSchema = {
command: {
o: "option",
v: "value"
}
}
const expectedOutput = [
[{
command: "command"
}],
[{
command: "command",
value: "value"
}],
[{
command: "command",
flags: {
option:true
}
}],
[{
command: "command",
flags: {
option:false
}
}],
[{
command: "command",
value: "value",
flags: {
option:true
}
}],
[{
command: "command",
value: "value",
flags: {
option:5,
value: true
}
},
{
command: "command",
value: "value",
flags: {
option:true,
value: "yes"
}
}
]
const parseCommand = command => {
console.log(command.split(';'))
}
commands.forEach(element => {
parseCommand(element)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment