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