Hey marc,
since the default value for a "Bool" is an undefined Bool, you can just
boolify whatever happens to be in :$diff, which will be False for "no
flag passed" or True for "flag passed and was True".
Hope that helps
- Timo
On 29/12/2021 13:00, Marc Chantreux wrote:
hello rakoons,
I have a script named fixlines which is basically
sub fixline (Str $line) { ... }
say fixline $_ for lines;
This is far enough for personal usage but i would like to release it
so i need a decent -h to be implemented and basically should look
like
Usage:
fixlines [--test] <files>
to do so, my
say fixline $_ for lines;
becomes
sub MAIN (
#| don't fix for real, just show the diff
Bool :$diff = False,
#| input files (stdin by default or explicit '-' in the list)
*@files
) {
+@files or @files = ('-');
my $argfiles = IO::ArgFiles.new(@files);
.&fixline.say for $argfiles.lines
}
This would be fair enough in any other langages but the whole thing looks
unelegant in a raku code.
So now I have 2 questions:
* I'm pretty sure i saw something like :!$test to express Bool :$test = False.
Did i just dreamed about it ?
* more importantly, is the a better choice than
+@files or @files = ('-');
my $argfiles = IO::ArgFiles.new(@files);
.&fixline.say for $argfiles.lines
I saw %*SUB-MAIN-OPTS in the documentation and was wondering if something like
%*SUB-MAIN-OPTS<ARGFILES>= my @files; #= input files, stdin if none
could be achievable by a module MAIN::UnixFilter i could put on Raku.land?
Regards,
marc