harthur / nomnom

Option parser for node with generated usage and commands
MIT License
471 stars 62 forks source link

New option type: map #32

Open gamtiq opened 10 years ago

gamtiq commented 10 years ago

Hello,

It would be useful to implement support for new option type (a possible name is map) that will allow gathering values of options with specified prefix into object. Specification field map could have string or boolean value. In the former case string specifies prefix to detect appropriate options. In the case of true value prefix is equal to full option name (value of specification field full).

Example:

var opts = require("nomnom")
        .option('application', {
            map: 'app',
            help: 'Application data'
        })
        .option('build', {
            map: true,
            help: 'Build settings'
        })
        .parse();

So

--app-name=MyApp --app-dir=some/path --build-mode=standalone --build-target=browser

would give:

{
    "application": {
        "name": "MyApp",
        "dir": "some/path"
    },
    "build": {
        "mode": "standalone",
        "target": "browser"
    }
}

Thanks, Denis

aoberoi commented 9 years ago

:+1: