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