Replace gruntmaster-* scripts with App::Cmd-based gm
[gruntmaster-data.git] / lib / Gruntmaster / App / Command / Show.pm
CommitLineData
92f74061
MG
1package Gruntmaster::App::Command::Show;
2
3use 5.014000;
4use warnings;
5
6our $VERSION = '5999.000_004';
7
8use Gruntmaster::App '-command';
9use Gruntmaster::Data;
10use POSIX qw/strftime/;
11
12sub usage_desc { '%c [-cjpu] show id' }
13
14my %TABLE = (
15 contests => \&show_contest,
16 jobs => \&show_job,
17 problems => \&show_problem,
18 users => \&show_user,
19);
20
21sub validate_args {
22 my ($self, $opt, $args) = @_;
23 my @args = @$args;
24 $self->usage_error('No table selected') unless $self->app->table;
25 $self->usage_error('Wrong number of arguments') if @args != 1;
26}
27
28sub execute {
29 my ($self, $opt, $args) = @_;
30 my ($obj) = @$args;
31 $TABLE{$self->app->table}->(db->select($self->app->table, '*', {id => $obj})->kv_list);
32}
33
34sub show_contest {
35 my (%columns) = @_;
36 $columns{$_} = strftime '%c', localtime $columns{$_} for qw/start stop/;
37
38 print <<END
39Name: $columns{name}
40Owner: $columns{owner}
41Start: $columns{start}
42Stop: $columns{stop}
43END
44}
45
46sub show_problem {
47 my (%columns) = @_;
48
49 no warnings 'uninitialized';
50 print <<END
51Name: $columns{name}
52Author: $columns{author}
53Statement written by: $columns{writer}
54Owner: $columns{owner}
55Level: $columns{level}
56Value (points): $columns{value}
57Private: @{[$columns{private} ? 'Yes' : 'No']}
58
59Generator: $columns{generator}
60Runner: $columns{runner}
61Judge: $columns{judge}
62Test count: $columns{testcnt}
63Time limit: $columns{timeout}
64Output limit (bytes): $columns{olimit}
65END
66}
67
681;
69__END__
This page took 0.014512 seconds and 4 git commands to generate.