From: Marius Gavrilescu Date: Fri, 17 Jan 2014 07:55:21 +0000 (+0200) Subject: Add gruntmaster-contest X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=4d44768e04bf89f1908e23edbe162a66ffcee02f;p=gruntmaster-page.git Add gruntmaster-contest --- diff --git a/Makefile.PL b/Makefile.PL index 3a7901c..cc79d4f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -4,7 +4,7 @@ use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Gruntmaster::Page', VERSION_FROM => 'lib/Gruntmaster/Page.pm', - EXE_FILES => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-problem gruntmaster-job/ ], + EXE_FILES => [ qw/gruntmaster-genpage gruntmaster-genallpages gruntmaster-paged gruntmaster-contest gruntmaster-problem gruntmaster-job/ ], ABSTRACT_FROM => 'lib/Gruntmaster/Page.pm', AUTHOR => 'Marius Gavrilescu ', MIN_PERL_VERSION => '5.14.0', diff --git a/gruntmaster-contest b/gruntmaster-contest new file mode 100755 index 0000000..e61a6c2 --- /dev/null +++ b/gruntmaster-contest @@ -0,0 +1,72 @@ +#!/usr/bin/perl -w +use v5.14; + +use Gruntmaster::Data qw/contests insert_contest remove_contest contest_name contest_owner contest_start contest_end/; + +use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; +use File::Slurp qw/read_file/; +use Term::ANSIColor qw/RED RESET/; +use POSIX qw/strftime/; +use Date::Parse qw/str2time/; + +################################################## + +sub cmd_help{ + exec perldoc => $0 +} + +sub cmd_list{ + local $, = "\n"; + say contests; +} + +sub cmd_show{ + local $_ = shift or goto &cmd_list; + say "Name: ", contest_name; + say "Owner: ", contest_owner; + say "Start: ", strftime '%c', localtime contest_start; + say "End: ", strftime '%c', localtime contest_end; +} + +sub cmd_add{ + my $id = shift; + my $name = prompt 'Contest name'; + my $owner = prompt 'Owner'; + my $start = str2time prompt 'Start time' or die 'Cannot parse time'; + my $end = str2time prompt 'End time' or die 'Cannot parse time'; + + insert_contest $id => name => $name, owner => $owner, start => $start, end => $end; +} + +sub cmd_rm{ + remove_contest shift; +} + +################################################## + +no strict 'refs'; +my $cmd = 'cmd_' . shift; +cmd_help unless exists $main::{$cmd}; +$cmd->(@ARGV) if exists $main::{$cmd}; + +1; +__END__ + +=encoding utf-8 + +=head1 NAME + +gruntmaster-contest - shell interface to Gruntmaster 6000 contests + +=head1 SYNOPSIS + + gruntmaster-contest list + gruntmaster-contest show id + gruntmaster-contest add id + gruntmaster-contest rm id + +=head1 DESCRIPTION + + + +=cut