https://github.com/nxadm/supermain
Raku MAIN() with superpowers
https://github.com/nxadm/supermain
cli command-line flags main parameters raku
Last synced: over 1 year ago
JSON representation
Raku MAIN() with superpowers
- Host: GitHub
- URL: https://github.com/nxadm/supermain
- Owner: nxadm
- License: artistic-2.0
- Created: 2019-12-06T09:07:42.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-11-02T10:04:50.000Z (over 4 years ago)
- Last Synced: 2025-02-16T09:51:06.835Z (over 1 year ago)
- Topics: cli, command-line, flags, main, parameters, raku
- Language: Raku
- Homepage:
- Size: 25.4 KB
- Stars: 12
- Watchers: 4
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SuperMAIN, Raku MAIN() with superpowers
[](https://travis-ci.org/nxadm/SuperMAIN)
[MAIN](https://docs.raku.org/language/create-cli#sub_MAIN) is one of the many
nice features that makes Raku a very fun language to work with. Command Line
Interfaces (CLI) can be easily be created in a very intuitive way.
This module adds features to MAIN without changing the syntax (or semantics).
Everything works as before, just with some nice-to-haves for the users of the
CLI.
## Features
The following features were added to MAIN:
- Allow named parameters to be used everywhere instead of only after the
positional parameters (corresponds with
`%SUB-MAIN-OPTS = True`):
```
$ prog.raku [--named1=] [--named2=]
$ prog.raku [--named1=] [--named2=]
$ prog.raku [--named1=] [--named2=]
```
- Allow spaces as separator between a named parameter and its values (the Raku
default is to only accept '=' as the separator).
```
$ prog.raku [--named1=]
$ prog.raku [--named1 ]
```
- Auto-alias named parameters without the need to declare an alias, e.g. to
make `-n` an alias of `--named`, you need to declare the alias in the
signature:
```raku
sub MAIN(Str :n(:$named)) { ... }
```
With SuperMain, an alias will be automatically created to the shortest *unique*
parameter identifier, e.g. for the signature
```raku
sub MAIN(Str :$named, Str :$other-named )) { ... }
```
the alias "-n" and "-o" will be accepted. If MAIN already has an alias for a
parameter no new alias will be created for that specific parameter.
```
$ prog.raku [--named=] [--other-named=]
$ prog.raku [-n=] [-o=]
$ prog.raku [--named ] [--other-named ]
$ prog.raku [-n ] [-o ]
```
## Usage
Add this to the script handling the CLI:
```raku
use SuperMAIN;
# That's it: just use `sub MAIN` or `multi MAIN` as usual.
```
## Installation
Through the ecosystem:
```
$ zef install SuperMAIN
```
Locally:
```
$ git clone https://github.com/nxadm/SuperMAIN
$ cd SuperMAIN
$ zef install .
```