IncludeIf: A digital space written in pencil
Searching for CLI modules on MetaCPAN returns 1690 results. And still I wrote another, Yet Another CLI framework. This is about why mine is the one you want to use.
CLI clients, we all write them, we all want them, but the boilerplate is just horrible. I wanted to get rid of it: Burn it with 🔥.
At my previous dayjob we had something I wrote, or co-wrote, my boss wanted a
sort of chef like API. It became zsknife, but had a huge downside. You needed
to register each command in the main module and I didn’t like that at all. I
forked the concept internally, made it so you didn’t needed to register, but it
lacked discovery.
When I wanted to write a git helper/client in Perl I took the pattern of my former (or back than current) employer and improved it. The rules where simple:
run() statement--help and --manThe use case for me was to have an API similar to this: Verbs that explain the action you want to execute. Perhaps a noun too, for when it’s about a domain of sorts:
I never finished the git helper project… but!
CLI modules on MetaCPAN, I saw a lot! And I wrote another, hence the name,
How does one use it? The meat of a command or subcommand is this:
That’s it. Help, manpages, option parsing (via
@ARGV gymnastics.
The hardest part of writing a new command is deciding what
it should do.
An example test for another module of mine:
You can also tell YA::CLI where to get the POD from, you just tell it where
to get it:
You don’t need to call
You can add POD to MyApp::CLI and have a help/man page, similar to what
happens when you run git without arguments.
You don’t need @ARGV, you can get the args via $self->_args. All options
that don’t have an attribute (via has) are stashed away in
$self->_cli_args->{'your-name-here'}.
Try it yourself:
Now you write the script:
You write some glue code:
And finally your first action handler:
Writing CLI scripts just became easy, no need to worry about Getopt::Long,
Pod::Usage and other boilerplate. Just write a testable module and you are
good to go.
YA::Goodbye