X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=lib%2FGruntmaster%2FApp%2FCommand%2FAdd.pm;h=36a8156a946df6970d2a488ca33afc9e1c4eb722;hb=e1b9f3ddadeb424826cacd6319cd065d9b008e95;hp=cc303011b298e093095e243687dcfb64c614178a;hpb=be8bda9654c6fbf7d331288c6c25becee5f6bc7f;p=gruntmaster-data.git diff --git a/lib/Gruntmaster/App/Command/Add.pm b/lib/Gruntmaster/App/Command/Add.pm index cc30301..36a8156 100644 --- a/lib/Gruntmaster/App/Command/Add.pm +++ b/lib/Gruntmaster/App/Command/Add.pm @@ -12,6 +12,7 @@ use Date::Parse qw/str2time/; use File::Slurp qw/read_file write_file/; use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; use JSON::MaybeXS qw/encode_json/; +use PerlX::Maybe; use Term::ANSIColor qw/RED RESET/; use constant LEVEL_VALUES => { @@ -24,22 +25,22 @@ use constant LEVEL_VALUES => { sub usage_desc { '%c [-cp] add id' } my %TABLE = ( - contest => \&add_contest, - problem => \&add_problem, + contests => \&add_contest, + problems => \&add_problem, ); sub validate_args { my ($self, $opt, $args) = @_; my @args = @$args; $self->usage_error('No table selected') unless $self->app->table; - $self->usage_error('Don\'t know how to add this object type') unless $TABLE{$self->app->object}; + $self->usage_error('Don\'t know how to add to this table') unless $TABLE{$self->app->table}; $self->usage_error('Wrong number of arguments') if @args != 1; } sub execute { my ($self, $opt, $args) = @_; my ($id) = @$args; - $TABLE{$self->app->object}->($self, $id); + $TABLE{$self->app->table}->($self, $id); } sub add_contest { @@ -47,8 +48,8 @@ sub add_contest { my $name = prompt 'Contest name'; my $owner = prompt 'Owner'; - my $start = str2time prompt 'Start time' or die 'Cannot parse time'; - my $stop = str2time prompt 'Stop time' or die 'Cannot parse time'; + my $start = str2time prompt 'Start time' or die "Cannot parse time\n"; + my $stop = str2time prompt 'Stop time' or die "Cannot parse time\n"; db->insert(contests => {id => $id, name => $name, owner => $owner, start => $start, stop => $stop}); } @@ -89,7 +90,7 @@ sub add_problem { if ($runner eq 'Verifier' || $runner eq 'Interactive') { say RED, 'WARNING: Runner::Interactive is experimental', RESET if $runner eq 'Interactive'; - $versource = prompt "[Runner::$runner] Verifier file name", -complete => 'filenames'; + $versource = read_file prompt "[Runner::$runner] Verifier file name", -complete => 'filenames'; $verformat = prompt "[Runner::$runner] Verifier format", -menu => [qw/C CPP MONO JAVA PASCAL PERL PYTHON/]; } @@ -106,18 +107,54 @@ sub add_problem { runner => $runner, judge => $judge, testcnt => $testcnt, + maybe private => $private, + maybe timeout => $timeout, + maybe olimit => $olimit, + maybe gensource => $gensource, + maybe genformat => $genformat, + maybe versource => $versource, + maybe verformat => $verformat, ); - $options{private} = $private if $private; - $options{timeout} = $timeout if $timeout; - $options{olimit} = $olimit if $olimit; $options{tests} = encode_json \@tests if @tests; - $options{gensource} = $gensource if $gensource; - $options{genformat} = $genformat if $genformat; - $options{versource} = $versource if $versource; - $options{verformat} = $verformat if $verformat; db->insert(problems => \%options); db->insert(contest_problems => {problem => $id, contest => $contest}) if $contest; } 1; __END__ + +=encoding utf-8 + +=head1 NAME + +Gruntmaster::App::Command::Add - add a problem or contest by answering a series of prompts + +=head1 SYNOPSIS + + gm -p add aplusb + gm -c add test_contest + +=head1 DESCRIPTION + +The add command creates a new problem or contest by prompting the user +for the properties of the new object. It takes a single argument, the +ID of the new object. + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Marius Gavrilescu, Emarius@ieval.roE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2014-2015 by Marius Gavrilescu + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.20.1 or, +at your option, any later version of Perl 5 you may have available. + + +=cut