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