<commit_before>package App::PocketPaas::Command::service;
use App::PocketPaas -command;

# ABSTRACT: manage pocketpaas services

use strict;
use warnings;

use App::PocketPaas::Service;

use Log::Log4perl qw(:easy);
use YAML qw(Dump);

sub opt_spec {
    return ( [ "name|n=s", "service name" ], [ "type|t=s", "service type" ],
    );
}

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

    my $command = shift @$args;

    if ( $command eq 'create' ) {

        my $name = _get_name_opt($opt);
        my $type = _get_type_opt($opt);

        my ( $service, $created )
            = App::PocketPaas::Service->provision( $name, $type );

        if ($created) {
            INFO("Service created.");
        }
        else {
            INFO("Service already exists.");
        }
    }
    elsif ( $command eq 'list' ) {

        # TODO
    }
    elsif ( $command eq 'env' ) {

        my $name = _get_name_opt($opt);

        my $service = App::PocketPaas::Service->get($name)
            || LOGEXIT("Service '$name' not found.");

        print $service->env;
    }
    elsif ( $command eq 'info' ) {

        my $name = _get_name_opt($opt);

        my $service = App::PocketPaas::Service->get($name);

        print Dump(
            {   name      => $service->name,
                type      => $service->type,
                docker_id => $service->docker_id,
                status    => $service->status,
            }
        );
    }
    elsif ( $command eq 'stop' ) {

        # TODO
    }
    elsif ( $command eq 'start' ) {

        # TODO
    }
    elsif ( $command eq 'destroy' ) {

        # TODO
    }
    elsif ( $command eq 'client' ) {

        # TODO
    }
    elsif ( $command eq 'shell' ) {

        # TODO
    }
}

sub _get_name_opt {
    return shift->{name}
        || LOGEXIT("Please provide a service name with --name");
}

sub _get_type_opt {
    return shift->{type}
        || LOGEXIT("Please provide a service type with --type");
}

1;<commit_msg>implement service client and shell<commit_after>package App::PocketPaas::Command::service;
use App::PocketPaas -command;

# ABSTRACT: manage pocketpaas services

use strict;
use warnings;

use App::PocketPaas::Service;

use Log::Log4perl qw(:easy);
use YAML qw(Dump);
use IPC::Run3;

sub opt_spec {
    return ( [ "name|n=s", "service name" ], [ "type|t=s", "service type" ],
    );
}

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

    my $command = shift @$args;

    if ( $command eq 'create' ) {

        my $name = _get_name_opt($opt);
        my $type = _get_type_opt($opt);

        my ( $service, $created )
            = App::PocketPaas::Service->provision( $name, $type );

        if ($created) {
            INFO("Service created.");
        }
        else {
            INFO("Service already exists.");
        }
    }
    elsif ( $command eq 'list' ) {

        # TODO
    }
    elsif ( $command eq 'env' ) {

        my $service = _get_service( _get_name_opt($opt) );

        print $service->env;
    }
    elsif ( $command eq 'info' ) {

        my $service = _get_service( _get_name_opt($opt) );

        print Dump(
            {   name      => $service->name,
                type      => $service->type,
                docker_id => $service->docker_id,
                status    => $service->status,
            }
        );
    }
    elsif ( $command eq 'stop' ) {

        # TODO
    }
    elsif ( $command eq 'start' ) {

        # TODO
    }
    elsif ( $command eq 'destroy' ) {

        # TODO
    }
    elsif ( $command eq 'client' ) {

        my $service = _get_service( _get_name_opt($opt) );

        # call out to servicepack
        run3 [ qw(svp client -c), $service->docker_id, ];
    }
    elsif ( $command eq 'shell' ) {

        my $service = _get_service( _get_name_opt($opt) );

        # call out to servicepack
        run3 [ qw(svp shell -c), $service->docker_id, ];
    }
}

sub _get_name_opt {
    return shift->{name}
        || LOGEXIT("Please provide a service name with --name");
}

sub _get_type_opt {
    return shift->{type}
        || LOGEXIT("Please provide a service type with --type");
}

sub _get_service {
    my $name = shift;
    return App::PocketPaas::Service->get($name)
        || LOGEXIT("Service '$name' not found.");
}

1;
{'fraction_non_alphanumeric': 0.14967259120673526, 'fraction_numerical': 0.001637043966323667, 'mean_word_length': 1.9557705597788528, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 32, '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': '233483', 'n_tokens_mistral': 1464, 'n_tokens_neox': 1406, 'n_words': 338}