3

I am using SailsJS for an application. From front-end i.e. NodeWebkituser will be entering a command which will be sent to server via sockets.

This command is parsed in back-end and a specific service/controller is called.

Socket code is as follows :

socket.on('command', {'command':'user -a -n abhishek -p 123456'})  

I am using JISON for command-line parsing which gets all options in command with their values.

Are there any command parsers better than JISON which I can use here.
Thanks in Advance

Abhishek
  • 1,999
  • 5
  • 26
  • 52

1 Answers1

5

You can also use minimist to parse the command.

var cmd = {'command':'user -a -n abhishek -p 123456'}
var argv = require('minimist')(cmd.command.split(' '))
console.dir(argv)

will produce:

{ _: [ 'user' ], a: true, n: 'abhishek', p: 123456 }

then you can:

if (argv['a']) ....
Miroslav Mocek
  • 857
  • 8
  • 4
  • @Mirosalv If possible could you help me out with this issue in minimist : http://stackoverflow.com/questions/27021844/command-validation-in-minimist – Abhishek Nov 19 '14 at 16:28