App-Koyomi

 view release on metacpan or  search on metacpan

lib/App/Koyomi/CLI.pm  view on Meta::CPAN

package App::Koyomi::CLI;

use strict;
use warnings;
use 5.010_001;
use Class::Accessor::Lite (
    ro => [qw/ctx/],
);
use File::Temp qw(tempfile);
use Getopt::Long qw(:config posix_default no_ignore_case no_ignore_case_always);
use IO::Prompt::Tiny qw(prompt);
use Log::Minimal env_debug => 'KOYOMI_LOG_DEBUG';
use Perl6::Slurp;
use Smart::Args;
use Text::ASCIITable;
use Text::Diff ();
use YAML::XS ();

use App::Koyomi::Context;
use App::Koyomi::JobTime::Formatter qw(str2time);
use App::Koyomi::JobTime::Object;

lib/App/Koyomi/CLI.pm  view on Meta::CPAN

    close $fh;
    system($editor, $tempfile);
    my $new_yaml = slurp($tempfile);
    unlink $tempfile;

    my $new_data = YAML::XS::Load($new_yaml);
    print YAML::XS::Dump($new_data) . "\n";
    my @new_times = map { str2time($_) } @{$new_data->{times}};
    $new_data->{times} = \@new_times;

    if (prompt('Add this job. OK? (y/n)', 'n') ne 'y') {
        infof('[add] Canceled.');
        return;
    }

    $ctx->datasource_job->create(data => $new_data, ctx => $ctx);

    infof('[add] Finished.');
}

sub list {

lib/App/Koyomi/CLI.pm  view on Meta::CPAN

    my $new_yaml = slurp($tempfile);
    unlink $tempfile;

    my $new_data = YAML::XS::Load($new_yaml);
    $new_yaml = YAML::XS::Dump($new_data);
    print Text::Diff::diff(\$yaml, \$new_yaml, +{ STYLE => 'Unified', CONTEXT => 5 });

    my @new_times = map { str2time($_) } @{$new_data->{times}};
    $new_data->{times} = \@new_times;

    if (prompt('Modify a job. OK? (y/n)', 'n') ne 'y') {
        infof('[modify] Canceled.');
        return;
    }

    $ctx->datasource_job->update_by_id(
        id => $job_id, data => $new_data, ctx => $ctx
    );

    infof('[modify] Finished.');
}

lib/App/Koyomi/CLI.pm  view on Meta::CPAN

        memo    => $job->memo,
    );

    my @times = map { $_->time2str } @{$job->times};
    $data{times} = \@times;

    my $yaml = YAML::XS::Dump(\%data);

    print $yaml . "\n";

    if (prompt('Delete this job. OK? (y/n)', 'n') ne 'y') {
        infof('[delete] Canceled.');
        return;
    }

    $ctx->datasource_job->delete_by_id(id => $job_id, ctx => $ctx);

    infof('[delete] Finished.');
}

sub _yaml_description {



( run in 1.597 second using v1.01-cache-2.11-cpan-6aa56a78535 )