Commit | Line | Data |
---|---|---|
92f74061 MG |
1 | package Gruntmaster::App::Command::Show; |
2 | ||
3 | use 5.014000; | |
4 | use warnings; | |
5 | ||
6 | our $VERSION = '5999.000_004'; | |
7 | ||
8 | use Gruntmaster::App '-command'; | |
9 | use Gruntmaster::Data; | |
10 | use POSIX qw/strftime/; | |
11 | ||
12 | sub usage_desc { '%c [-cjpu] show id' } | |
13 | ||
14 | my %TABLE = ( | |
15 | contests => \&show_contest, | |
16 | jobs => \&show_job, | |
17 | problems => \&show_problem, | |
18 | users => \&show_user, | |
19 | ); | |
20 | ||
21 | sub 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 | ||
28 | sub execute { | |
29 | my ($self, $opt, $args) = @_; | |
30 | my ($obj) = @$args; | |
26d0f7b4 | 31 | $TABLE{$self->app->table}->(%{db->select($self->app->table, '*', {id => $obj})->hash}); |
92f74061 MG |
32 | } |
33 | ||
34 | sub show_contest { | |
35 | my (%columns) = @_; | |
36 | $columns{$_} = strftime '%c', localtime $columns{$_} for qw/start stop/; | |
37 | ||
38 | print <<END | |
39 | Name: $columns{name} | |
40 | Owner: $columns{owner} | |
41 | Start: $columns{start} | |
42 | Stop: $columns{stop} | |
43 | END | |
44 | } | |
45 | ||
dfcf2c13 MG |
46 | sub show_job { |
47 | my (%columns) = @_; | |
48 | $columns{date} = strftime '%c', localtime $columns{date}; | |
49 | ||
50 | no warnings 'uninitialized'; | |
51 | print <<END | |
52 | Problem: $columns{problem} | |
53 | Contest: $columns{contest} | |
54 | Owner: $columns{owner} | |
55 | Date: $columns{date} | |
56 | Private: @{[$columns{private} ? 'Yes' : 'No']} | |
57 | Format: $columns{format} | |
58 | Result: $columns{result} ($columns{result_text}) | |
59 | END | |
60 | } | |
61 | ||
92f74061 MG |
62 | sub show_problem { |
63 | my (%columns) = @_; | |
64 | ||
65 | no warnings 'uninitialized'; | |
66 | print <<END | |
67 | Name: $columns{name} | |
68 | Author: $columns{author} | |
69 | Statement written by: $columns{writer} | |
70 | Owner: $columns{owner} | |
71 | Level: $columns{level} | |
72 | Value (points): $columns{value} | |
73 | Private: @{[$columns{private} ? 'Yes' : 'No']} | |
74 | ||
75 | Generator: $columns{generator} | |
76 | Runner: $columns{runner} | |
77 | Judge: $columns{judge} | |
78 | Test count: $columns{testcnt} | |
79 | Time limit: $columns{timeout} | |
80 | Output limit (bytes): $columns{olimit} | |
81 | END | |
82 | } | |
83 | ||
dfcf2c13 MG |
84 | sub show_user { |
85 | my (%columns) = @_; | |
86 | $columns{since} = strftime '%c', localtime $columns{since}; | |
87 | ||
88 | no warnings 'uninitialized'; | |
89 | print <<END | |
90 | Email: $columns{name} <$columns{email}> | |
91 | Phone: $columns{phone} | |
92 | Since: $columns{since} | |
93 | Admin: @{[$columns{admin} ? 'Yes' : 'No']} | |
94 | Level: $columns{level} | |
95 | University: $columns{university} | |
96 | Town: $columns{town} | |
97 | Country: $columns{country} | |
98 | END | |
99 | } | |
100 | ||
92f74061 MG |
101 | 1; |
102 | __END__ |