<commit_before>package Tapper::CLI::Testrun::Command::deletehost;

use 5.010;
use strict;
use warnings;

use parent 'App::Cmd::Command';
use Tapper::Model 'model';

sub abstract {
        'Delete a host'
}

sub opt_spec {
        return (
                [ "verbose|v",  "some more informational output" ],
                [ "really",   "really execute the command"     ],
                [ "id=s@",    "delete particular host",    ],
               );
}

sub usage_desc {
        my $allowed_opts = join ' | ', map { '--'.$_ } _allowed_opts();
        "tapper-testrun deletehost [ " . $allowed_opts ." ]";
}

sub _allowed_opts {
        my @allowed_opts = map { $_->[0] } opt_spec();
}

sub _extract_bare_option_names {
        map { my $x = $_; $x =~ s/=.*//; $x } _allowed_opts();
}

sub validate_args {
        my ($self, $opt, $args) = @_;


        my $msg = "Unknown option";
        $msg   .= ($args and $#{$args} >=1) ? 's' : '';
        $msg   .= ": ";
        say STDERR $msg, join(', ',@$args) if ($args and @$args);

        my $allowed_opts_re = join '|', _extract_bare_option_names();
        die "Really? Then add --really to the options.\n" unless $opt->{really};

        return 1 if grep /$allowed_opts_re/, keys %$opt;
        die $self->usage->text;
}

sub execute {
        my ($self, $opt, $args) = @_;

 ID:
        foreach my $id (@{$opt->{id}}){
                my $host = model('TestrunDB')->resultset('Host')->find($id);
                next ID if not $host;
                my $name = $host->name;
                $host->delete();
                say "Deleted host $name with id $id" if $opt->{verbose};
        }<commit_msg>[FEAT] delete host by setting deleted flag<commit_after>package Tapper::CLI::Testrun::Command::deletehost;

use 5.010;
use strict;
use warnings;

use parent 'App::Cmd::Command';
use Tapper::Model 'model';

sub abstract {
        'Delete a host'
}

sub opt_spec {
        return (
                [ "verbose|v",  "some more informational output" ],
                [ "really",   "really execute the command"     ],
                [ "id=s@",    "delete particular host",    ],
                [ "name=s@",  "Select host to delete by name" ],
               );
}

sub usage_desc {
        my $allowed_opts = join ' | ', map { '--'.$_ } _allowed_opts();
        "tapper-testrun deletehost [ " . $allowed_opts ." ]";
}

sub _allowed_opts {
        my @allowed_opts = map { $_->[0] } opt_spec();
}

sub _extract_bare_option_names {
        map { my $x = $_; $x =~ s/=.*//; $x } _allowed_opts();
}

sub validate_args {
        my ($self, $opt, $args) = @_;


        my $msg = "Unknown option";
        $msg   .= ($args and $#{$args} >=1) ? 's' : '';
        $msg   .= ": ";
        say STDERR $msg, join(', ',@$args) if ($args and @$args);

        my $allowed_opts_re = join '|', _extract_bare_option_names();
        die "Really? Then add --really to the options.\n" unless $opt->{really};

        return 1 if grep /$allowed_opts_re/, keys %$opt;
        die $self->usage->text;
}

sub execute {
        my ($self, $opt, $args) = @_;

 NAME:
        foreach my $name (@{$opt->{name}}) {
                my $host = model('TestrunDB')->resultset('Host')->search({name => $name})->first;
                push @{$opt->{id}}, $host->id;
        }

 ID:
        foreach my $id (@{$opt->{id}}){
                my $host = model('TestrunDB')->resultset('Host')->find($id);
                if (not $host) {
                        warn "No host with $id";
                        next ID;
                }
                my $name = $host->name;
                $host->active(0);
                $host->is_deleted(1);
                $host->update();
                say "Deleted host $name with id $id" if $opt->{verbose};
        }
{'fraction_non_alphanumeric': 0.17712470214455917, 'fraction_numerical': 0.004236166269526079, 'mean_word_length': 1.8883792048929664, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 34, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '123649', 'n_tokens_mistral': 1265, 'n_tokens_neox': 1195, 'n_words': 318}