adaltas / node-shell

Command line arguments parser and stringifier

Home Page:https://shell.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

config: complement default flatten mode with extended mode

sergkudinov opened this issue · comments

Parameters are currently merged when multiple commands are being used. This provide a limitation where the same parameter name (defined by the options and main properties) will collide when declared in sub commands. The goal is to keep the flatten mode it ease of usage while supporting an alternative extended mode which, while being more verbose to use, will get around this limitation.

For example, considering the following configuration:

{ "options":
  { "name": "my_opt" } },
{ "commands":
  { "name": "my_cmd",
    "options":
    { "name": "my_opt" } } } }

The "my_opt" option is declared twice and can not obtain of all the parameters are merged in the resulting parameter object. For the command ./myapp --my_opt "value 1" my_cmd --my_opt "value 2, the object returned by parsewould be:

{ "command": "my_cmd",
  "my_opt": "value 2" }

In the extended mode, the output would look like:

[ { "my_opt": "value 1" },
  { "command": "my_arg",
    "my_opt": "value 2" } ]