]> iEval git - gruntmaster-page.git/blobdiff - gruntmaster-problem
Improve standings
[gruntmaster-page.git] / gruntmaster-problem
index 611235f635794d4be42cf53c7d06b9482366575d..80aa68d7485f8d38f5894ffe395d4c4912d96bd1 100755 (executable)
@@ -1,14 +1,18 @@
 #!/usr/bin/perl -w
 use v5.14;
 
-use Gruntmaster::Data qw/insert_problem remove_problem set_problem_meta problems/;
+use Gruntmaster::Data;
+use Gruntmaster::Page::Submit;
 
 use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ];
 use File::Slurp qw/read_file/;
 use Term::ANSIColor qw/RED RESET/;
+use Getopt::Long qw/GetOptions/;
 
 ##################################################
 
+my $contest;
+
 sub cmd_help{
        exec perldoc => $0
 }
@@ -17,16 +21,15 @@ sub prompt_file{
        my ($meta, $name, $prefix) = @_;
        my $filename = prompt '$prefix filename', -complete => 'filenames';
        $meta->{files}{$name}{content} = read_file $filename;
-       $meta->{files}{$name}{format} = prompt '$prefix format', -menu => [keys Gruntmaster::Page::Log::FORMAT_EXTENSION()];
+       $meta->{files}{$name}{format} = prompt '$prefix format', -menu => Gruntmaster::Page::Submit::FORMATS;
        $meta->{files}{$name}{name} = prompt "$prefix filename [$filename]", -default => $filename;
-
 }
 
 sub cmd_add{
        my $id = shift;
-       my $contest = prompt 'Contest';
-       local $Gruntmaster::Data::contest = $contest if $contest;
        my $name = prompt 'Problem name';
+       my $author = prompt 'Problem author (full name)';
+       my $owner = prompt 'Problem owner (username)';
        my $level = prompt 'Problem level', -menu => "beginner\neasy\nmedium\nhard";
        my $statement = read_file prompt 'File with problem statement', -complete => 'filenames';
        my %meta;
@@ -61,18 +64,30 @@ sub cmd_add{
                prompt_file int => '[Runner::Interactive] Interactive verifier';
        }
 
-       insert_problem $id => name => $name, level => $level, statement => $statement;
+       insert_problem $id => name => $name, level => $level, statement => $statement, author => $author, owner => $owner;
        set_problem_meta $id => \%meta;
+       PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
+       PUBLISH genpage => $contest ? "ct/$contest/pb/$id.html" : "pb/$id.html";
+}
+
+sub cmd_set{
+       my $file;
+       GetOptions ( 'file!' => \$file );
+       my ($id, %values) = @ARGV;
+       %values = map { $_ => scalar read_file $values{$_} } keys %values if $file;
+       edit_problem $id => %values;
+       PUBLISH genpage => 'pb/index.html';
+       PUBLISH genpage => "pb/$id.html";
 }
 
 sub cmd_list{
-       my $contest = shift;
-       local $Gruntmaster::Data::contest = $contest if $contest;
-       print problems;
+       local $, = "\n";
+       say problems;
 }
 
 sub cmd_rm{
-       remove_problem shift
+       remove_problem shift;
+       PUBLISH genpage => $contest ? "ct/$contest/pb/index.html" : 'pb/index.html';
 }
 
 sub cmd_show{
@@ -81,9 +96,11 @@ sub cmd_show{
 
 ##################################################
 
-no strict 'refs';
+GetOptions ( 'contest=s' => \$contest );
+local $Gruntmaster::Data::contest = $contest;
 my $cmd = 'cmd_' . shift;
 cmd_help unless exists $main::{$cmd};
+no strict 'refs';
 $cmd->(@ARGV) if exists $main::{$cmd};
 
 1;
This page took 0.025727 seconds and 4 git commands to generate.