Help language development. Donate to The Perl Foundation

shorten-sub-commands zef:lizmat last updated on 2022-02-09

87eae43125ff23f2cb500a74f1477b92d9127d9e/

Actions Status

NAME

shorten-sub-commands - allow partial specification of sub-commands

SYNOPSIS

# in script "frobnicate"
multi sub MAIN("foozle")  { say "foozle"  }
multi sub MAIN("barabas") { say "barabas" }
multi sub MAIN("bazzie")  { say "bazzie"  }
use shorten::sub::commands &MAIN;

    $ raku frobnicate foo
    foozle
    $ raku frobnicate ba
    'ba' is ambiguous, matches: barabas bazzie
    $ raku frobnicate bar
    barabas

DESCRIPTION

shorten::sub::commands is a helper module intended to be used for command-line application that have a sub-command structure (in which the first positional parameter indicates what needs to be done, and there is a separate candidate to handle execution of that command).

When used after all MAIN candidates have been defined, it will add another candidate that will allow to shorten the command names to be as short as possible (e.g. just "foo" in the example above, or even just "f" as there is only one candidate that starts with "f". Numeric subcommands are also supported, but they will be matched as strings (so 4 on the command line will match 42 in the signature).

Special care has been taken to ensure that re-dispatch doesn't devolved into an infinite loop.

AUTHOR

Elizabeth Mattijsen [email protected]

Source can be located at: https://github.com/lizmat/shorten-sub-commands . Comments and Pull Requests are welcome.

COPYRIGHT AND LICENSE

Copyright 2022 Elizabeth Mattijsen

This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.