-
Notifications
You must be signed in to change notification settings - Fork 227
Open
Labels
Description
miller verbs are great. Easy to use, saves key strokes and easy to understand. It would be nice to extend those benefits to user-defined verbs.
Proposal
Users can create new verbs by registering them using below function. This function will be called in a miller file loaded using --[m]load.
register_verb(func, name, description, flags)
nameis stringdescriptionis string for use inmlr helpflagsis an array offlagwhich is a map with keysshort,long,description,type,default. At least one ofshortorlongis required. Rest are of them are optional.typecan be"bool","single", or"multi". default is"single"."multi"means it can occur multiple times. e.g.verb -f arg1-f arg2 -f arg3. Accessed in the function as a listarg["f"]will be["arg1", "arg2", "arg3"].- when
typeisbool, it can be turned off with--no-prefix. i.e.--no-longname. boolflags can be coalesced. i.e.-xyz foois same as-x -y -z foo.- one of the flag can have
longset to[POS]which refers to positional argument.typeis alwayssingle funcis a miller function that will be called with one argumentargs. It is a map with passed flags.
Example
register_verb(bconv, "bconv", "Convert bytes to KB, MB, GB or TB", [
{
"short": "s",
"long":"source",
"type":"single",
"default":"B",
"description":"Source unit. One of B, KB, MB, GB"
},
{
"short": "t",
"long":"target",
"type":"single",
"default": "auto",
"description":"Target unit. One of B, KB, MB, GB, auto. If auto, appropriate unit is chosen"
},
{
"short": "x",
"long":"suffix",
"type":"bool",
"default":true,
"description":"Add suffix after conversion. E.g. 2.4 MB"
},
{
"long":"[POS]",
"description":"comma separated list of fields to convert"
}
]
)
func bconf(args) {
if (args["suffix"]) { ... }
}
Namespace
- Keep user defined verbs same namespace as standard ones. (similar to user defined functions).
- Have user-defined verbs start with capital letter. Similar to
gofunctions. - [my choice] Prefix user-defined verbs with
u:or a different prefix. E.g.mlr --l2p u:bconv Memory,Swap then head.
aborruso