eserte / Doit

a scripting framework
https://metacpan.org/release/Doit
0 stars 0 forks source link

Feature Request: $doit->loop #6

Open srchulo opened 5 years ago

srchulo commented 5 years ago

It would be really cool if Doit supported loops/iteration. Currently if I have:

for (0..$num) {
    $doit->run();
}

The --dry-run output will only show the items in the loop once. It would be nice if there was something like:

$doit->range(0, $num, sub {
    $doit->run();
});

Then the output could maybe show something like "running this command from 0 to x" and the INFO logs could maybe be indented to indicate a loop?. I called the above range, because for numbers you may want to show the range you're running over instead of all possibilities, but for a general loop or foreach may want to show each of the items.

srchulo commented 5 years ago

Whoops, looks like this may actually show more than the one when $num > 0, and none when $num == 0. However, I had $num set to50,000, and it was not very readable due to the large number.

srchulo commented 5 years ago

I currently did this as a work around:

    if ($doit->is_dry_run) {
        info "Dry run, next set of statements will run in a loop from the number returned above. You will only see one set now.";
        info "-----------------------------------";
        $num = 1;
    }
    for (0..$num) {
        $doit->run();
    }

    if ($doit->is_dry_run) {
        info "-----------------------------------";
    }