> On Apr 1, 2025, at 03:55, ToddAndMargo via perl6-users <perl6-users@perl.org>
> wrote:
--snip--
> I have the following run string:
> raku C:\NtUtil\RLA.Backup.raku --rotates 345 --UNC_BackupPath
> \\192.168.240.10\Backup\MyDocsBackup\backup1 --debug
>
>
> use Getopt::Long; # get-options
> get-options('debug' => $CommandLine.debug );
>
> error out with
> No such method 'debug' for invocant of type 'List'
>
> What am I doing wrong?
You are not giving us a
https://en.wikipedia.org/wiki/Minimal_reproducible_example , so I am having to
guess.
My guess is that you have defined `$CommandLine` in a way that lacks a
writeable `.debug` method.
You *could* simplify the call to `get-options` to use a simple temp variables
(similar to the documentation), then copy the temp into some `debug` and
similar parts of your more complex `$CommandLine` data structure, but I expect
your full code is trying to avoid such temp vars.
Here is a complete runnable program to demonstrate skipping any temp vars,
using a wild guess that `$CommandLine` is the sole instance of a OO data class:
class CommandLineInfo {
has Bool $.debug is rw = False;
}
my CommandLineInfo $CommandLine .= new;
use Getopt::Long;
get-options( 'debug' => $CommandLine.debug );
say $CommandLine.debug; # Will be `True` or `False`, depending on
command-line arg.
If this code does not align with (and is not adaptable to) your use case, we
(or at least *I*) will need more information from you, especially the
definition of `$CommandLine` in your current code.
As always, minimal *runnable* code will allow any of us to provide an answer to
you more quickly.
FWIW, I use `sub MAIN`, but if I were to use `Getopt::Long`, I might use the
(under-documented) method of having `get-options` build the data structure
itself:
use Getopt::Long;
my %CommandLine = get-options( 'debug', 'rotates=i', 'UNC_BackupPath=p'
).hash;
say ?%CommandLine<debug>; # Just the `debug` argument, forced to Bool
say %CommandLine.raku; # All the specified arguments.
> Many thanks,
> -T
You are very welcome!
--
Bruce Gray (Util of PerlMonks)