App-TimeTracker
view release on metacpan or search on metacpan
lib/App/TimeTracker/Command/Core.pm view on Meta::CPAN
say sprintf( $padding . $tagpadding . $format,
$tag, $self->beautify_seconds($time) );
}
}
}
foreach my $child ( sort keys %{ $projects->{$project}{children} } ) {
$self->_print_report_tree( $report, $projects, $child,
$padding . ' ', $tagpadding );
}
}
sub cmd_recalc_trackfile {
my $self = shift;
my $file = $self->trackfile;
unless ( -e $file ) {
$file =~ /(?<year>\d\d\d\d)(?<month>\d\d)\d\d-\d{6}_\w+\.trc/;
if ( $+{year} && $+{month} ) {
$file = $self->home->file( $+{year}, $+{month}, $file )->stringify;
unless ( -e $file ) {
error_message( "Cannot find file %s", $self->trackfile );
exit;
}
}
}
my $task = App::TimeTracker::Data::Task->load($file);
$task->save( $self->home );
say "recalced $file";
}
sub cmd_show_config {
my $self = shift;
warn Data::Dumper::Dumper $self->config;
}
sub cmd_init {
my ( $self, $cwd ) = @_;
$cwd ||= Path::Class::Dir->new->absolute;
if ( -e $cwd->file('.tracker.json') ) {
error_message(
"This directory is already set up.\nTry 'tracker show_config' to see the current aggregated config."
);
exit;
}
my $project;
if( $self->has_current_project ) {
$project = $self->_current_project;
} else {
my @dirs = $cwd->dir_list;
$project = $dirs[-1];
}
my $fh = $cwd->file('.tracker.json')->openw;
say $fh <<EOCONFIG;
{
"project":"$project"
}
EOCONFIG
my $projects_file = $self->home->file('projects.json');
my $coder = JSON::XS->new->utf8->pretty->canonical->relaxed;
if ( -e $projects_file ) {
my $projects = $coder->decode( scalar $projects_file->slurp );
$projects->{$project} =
$cwd->file('.tracker.json')->absolute->stringify;
$projects_file->spew( $coder->encode($projects) );
}
say "Set up this directory for time-tracking via file .tracker.json";
}
sub cmd_plugins {
my $self = shift;
my $base =
Path::Class::file( $INC{'App/TimeTracker/Command/Core.pm'} )->parent;
my @hits;
while ( my $file = $base->next ) {
next unless -f $file;
next if $file->basename eq 'Core.pm';
my $plugin = $file->basename;
$plugin =~ s/\.pm$//;
push( @hits, $plugin );
}
say "Installed plugins:\n " . join( ', ', @hits );
}
sub cmd_version {
my $self = shift;
say "This is App::TimeTracker, version " . App::TimeTracker->VERSION;
exit;
}
sub cmd_commands {
my $self = shift;
my @commands;
foreach my $method ( $self->meta->get_all_method_names ) {
next unless $method =~ /^cmd_/;
$method =~ s/^cmd_//;
push( @commands, $method );
}
@commands = sort @commands;
if ( $self->can('autocomplete')
&& $self->autocomplete ) {
say join( ' ', @commands );
}
else {
say "Available commands:";
foreach my $command (@commands) {
say "\t$command";
}
}
exit;
}
sub _load_attribs_worked {
my ( $class, $meta ) = @_;
$meta->add_attribute(
( run in 0.960 second using v1.01-cache-2.11-cpan-39bf76dae61 )