pericmd 037: More on tab completion (8): x.schema.entity

If you have a lot of functions each with several arguments, you can end up with adding a lot of completion routines for them. And chances are, a lot of them have the same completion routines, for example many of your “user” arguments probably are to be completed with a list of Unix usernames, “file” arguments are filenames, and so on.

Instead of explicitly adding completion routines, you can now also just add an x.schema.entity attribute to your function argument’s specification to mark what kind of entity this argument is.

Perinci::CmdLine will then look for corresponding Perinci::Sub::ArgEntity::* module and inside the module will search for complete_arg_val function. This function will then be used for the completion routine.

There is also the corresponding x.schema.element_entity to be used for the element_completion property.

Currently there is only a handful (or less than a handful) of Perinci::Sub::ArgEntity::* modules on CPAN. I plan to add some more. I also plan to create a Dist::Zilla plugin so that CLI applications having x.schema.{entity,element_entity} attributes in their Rinci metadata will have the corresponding Perinci::Sub::ArgEntity:* modules searched on CPAN and added automatically as prerequisites.

Also of note is that the x.schema.entity attribute is useful for other purposes too, but this is the topic for another blog post.


x.schema.entity is a temporary workaround. Since this is just an issue of types, eventually this information should be put in the schema property, where instead of something like ["str*", min_len=>1, max_len=>255] you specify a schema like ["filename*"] and then the tab completion subsystem can get hints from the type. Sah is capable of this subtyping, but the implementation modules haven’t caught up yet, so I’m keeping the schemas to basic/builtin types and add more refined information in the x.schema.entity attributes for now.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s