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