]> iEval git - gruntmaster-data.git/blobdiff - lib/Gruntmaster/App/Command/Show.pm
Replace gruntmaster-* scripts with App::Cmd-based gm
[gruntmaster-data.git] / lib / Gruntmaster / App / Command / Show.pm
diff --git a/lib/Gruntmaster/App/Command/Show.pm b/lib/Gruntmaster/App/Command/Show.pm
new file mode 100644 (file)
index 0000000..0c06d57
--- /dev/null
@@ -0,0 +1,69 @@
+package Gruntmaster::App::Command::Show;
+
+use 5.014000;
+use warnings;
+
+our $VERSION = '5999.000_004';
+
+use Gruntmaster::App '-command';
+use Gruntmaster::Data;
+use POSIX qw/strftime/;
+
+sub usage_desc { '%c [-cjpu] show id' }
+
+my %TABLE = (
+       contests => \&show_contest,
+       jobs     => \&show_job,
+       problems => \&show_problem,
+       users    => \&show_user,
+);
+
+sub validate_args {
+       my ($self, $opt, $args) = @_;
+       my @args = @$args;
+       $self->usage_error('No table selected') unless $self->app->table;
+       $self->usage_error('Wrong number of arguments') if @args != 1;
+}
+
+sub execute {
+       my ($self, $opt, $args) = @_;
+       my ($obj) = @$args;
+       $TABLE{$self->app->table}->(db->select($self->app->table, '*', {id => $obj})->kv_list);
+}
+
+sub show_contest {
+       my (%columns) = @_;
+       $columns{$_} = strftime '%c', localtime $columns{$_} for qw/start stop/;
+
+       print <<END
+Name: $columns{name}
+Owner: $columns{owner}
+Start: $columns{start}
+Stop: $columns{stop}
+END
+}
+
+sub show_problem {
+       my (%columns) = @_;
+
+       no warnings 'uninitialized';
+       print <<END
+Name: $columns{name}
+Author: $columns{author}
+Statement written by: $columns{writer}
+Owner: $columns{owner}
+Level: $columns{level}
+Value (points): $columns{value}
+Private: @{[$columns{private} ? 'Yes' : 'No']}
+
+Generator: $columns{generator}
+Runner: $columns{runner}
+Judge: $columns{judge}
+Test count: $columns{testcnt}
+Time limit: $columns{timeout}
+Output limit (bytes): $columns{olimit}
+END
+}
+
+1;
+__END__
This page took 0.020945 seconds and 4 git commands to generate.