dthree / vorpal

Node's framework for interactive CLIs

Home Page:http://vorpal.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Plural forms, shortened words or alternatives in the command string.

robblovell opened this issue · comments

I would like to suggest a new feature for vorpal (forgive me if i didn't see that this is implemented in the documentation or there is another issue with this suggestion). The idea is to provide a way to give fixed alternatives in command lists, kubernetes style.

Kuberentes allows implementations like so:

kubectl get apps -n aNamespace
kubectl get app -n aNamespace

Where I work, we are attempting to create commands with vorpal like:

command app services list [names...]
command app service list [names...]
command apps service list [names...]
command apps services list [names...]

command apps log
command apps logs
command app log
command app logs

Where the command requires 'app' or 'service', but also allows shorthands or plural forms like apps, service, services, svc etc.

This sort of thing can be implemented with <> brackets where the code validates what the user put after the code has entered the 'action' clause. But, we want the help to show what is possible in the command sequence. The '.alias' function could be used here too, but only in limited cases (I think).

You could do this so that the check happens before the 'action' clause in the parser with a construct like this:

.command('{app,apps} {service,services,svc,svcs} list [names...]')
.command('{app,apps} {log,logs} list [names...]')
.command('{get,grab,pull,fetch,find} {app,apps} [names...]')

Using delimiters that aren't used yet, not <> or [], which leaves {} as a good candidate.