Commit | Line | Data |
---|---|---|
014ee8a6 MG |
1 | #!/usr/bin/perl -w |
2 | use v5.14; | |
3 | ||
4 | use Gruntmaster::Data; | |
5 | ||
6 | use IO::Prompter [ -style => 'bold', '-stdio', '-verbatim' ]; | |
7 | use POSIX qw/strftime/; | |
8 | use Date::Parse qw/str2time/; | |
9 | ||
10 | ################################################## | |
11 | ||
30e287c3 MG |
12 | my $dsn = $ENV{GRUNTMASTER_DSN} // 'dbi:Pg:'; |
13 | my $db = Gruntmaster::Data->connect($dsn); | |
08b6a201 | 14 | |
014ee8a6 MG |
15 | sub cmd_help{ |
16 | exec perldoc => $0 | |
17 | } | |
18 | ||
19 | sub cmd_list{ | |
20 | local $, = "\n"; | |
4af36605 | 21 | say map { $_->id } $db->contests->all; |
014ee8a6 MG |
22 | } |
23 | ||
24 | sub cmd_show{ | |
4af36605 MG |
25 | my %columns = $db->contest(shift)->get_columns; |
26 | $columns{$_} = strftime '%c', localtime $columns{$_} for qw/start stop/; | |
27 | print <<END | |
28 | Name: $columns{name} | |
29 | Owner: $columns{owner} | |
30 | Start: $columns{start} | |
31 | Stop: $columns{stop} | |
32 | END | |
014ee8a6 MG |
33 | } |
34 | ||
35 | sub cmd_add{ | |
edfc5928 | 36 | my ($id) = @_; |
014ee8a6 MG |
37 | my $name = prompt 'Contest name'; |
38 | my $owner = prompt 'Owner'; | |
39 | my $start = str2time prompt 'Start time' or die 'Cannot parse time'; | |
08b6a201 | 40 | my $stop = str2time prompt 'Stop time' or die 'Cannot parse time'; |
014ee8a6 | 41 | |
edfc5928 MG |
42 | $db->contests->create({id => $id, name => $name, owner => $owner, start => $start, stop => $stop}); |
43 | purge '/ct/'; | |
014ee8a6 MG |
44 | } |
45 | ||
46 | sub cmd_rm{ | |
edfc5928 MG |
47 | my ($id) = @_; |
48 | $db->contest(shift)->delete; | |
49 | purge '/ct/'; | |
50 | purge "/ct/$id"; | |
4af36605 MG |
51 | } |
52 | ||
53 | sub cmd_get{ | |
54 | my ($id, $col) = @_; | |
55 | say $db->contest($id)->get_column($col) | |
56 | } | |
57 | ||
58 | sub cmd_set{ | |
59 | my ($id, %values) = @_; | |
edfc5928 MG |
60 | $db->contest($id)->update(\%values); |
61 | purge '/ct/'; | |
62 | purge "/ct/$id"; | |
014ee8a6 MG |
63 | } |
64 | ||
65 | ################################################## | |
66 | ||
67 | no strict 'refs'; | |
68 | my $cmd = 'cmd_' . shift; | |
69 | cmd_help unless exists $main::{$cmd}; | |
70 | $cmd->(@ARGV) if exists $main::{$cmd}; | |
71 | ||
72 | 1; | |
73 | __END__ | |
74 | ||
75 | =encoding utf-8 | |
76 | ||
77 | =head1 NAME | |
78 | ||
79 | gruntmaster-contest - shell interface to Gruntmaster 6000 contests | |
80 | ||
81 | =head1 SYNOPSIS | |
82 | ||
83 | gruntmaster-contest list | |
84 | gruntmaster-contest show id | |
85 | gruntmaster-contest add id | |
86 | gruntmaster-contest rm id | |
4af36605 MG |
87 | gruntmaster-contest get id key |
88 | gruntmaster-contest set id key value | |
014ee8a6 MG |
89 | |
90 | =head1 DESCRIPTION | |
91 | ||
e90402be MG |
92 | gruntmaster-contest is a tool for managing contests. |
93 | ||
94 | =over | |
95 | ||
96 | =item B<list> | |
97 | ||
98 | Prints the list of contests. | |
99 | ||
100 | =item B<show> I<id> | |
101 | ||
102 | Prints detailed information about the contest with id I<id>. | |
103 | ||
104 | =item B<add> I<id> | |
105 | ||
106 | Adds a new contest with id I<id>. | |
107 | ||
108 | =item B<rm> I<id> | |
109 | ||
4af36605 MG |
110 | Removes the contest with id I<id>. |
111 | ||
112 | =item B<set> I<id> I<key> I<value> | |
113 | ||
114 | Sets the I<key> configuration option of contest I<id> to I<value>. | |
115 | ||
116 | =item B<get> I<id> I<key> | |
117 | ||
118 | Get the value of the I<key> configuration option of contest I<id>. | |
e90402be MG |
119 | |
120 | =back | |
121 | ||
122 | =head1 AUTHOR | |
123 | ||
124 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
125 | ||
126 | =head1 COPYRIGHT AND LICENSE | |
127 | ||
128 | Copyright (C) 2014 by Marius Gavrilescu | |
129 | ||
4af36605 MG |
130 | This library is free software; you can redistribute it and/or modify |
131 | it under the same terms as Perl itself, either Perl version 5.18.1 or, | |
132 | at your option, any later version of Perl 5 you may have available. | |
014ee8a6 MG |
133 | |
134 | ||
135 | =cut |