]>
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 | ||
12 | sub cmd_help{ | |
13 | exec perldoc => $0 | |
14 | } | |
15 | ||
16 | sub cmd_list{ | |
17 | local $, = "\n"; | |
18 | say contests; | |
19 | } | |
20 | ||
21 | sub cmd_show{ | |
22 | local $_ = shift or goto &cmd_list; | |
23 | say "Name: ", contest_name; | |
24 | say "Owner: ", contest_owner; | |
25 | say "Start: ", strftime '%c', localtime contest_start; | |
26 | say "End: ", strftime '%c', localtime contest_end; | |
27 | } | |
28 | ||
29 | sub cmd_add{ | |
30 | my $id = shift; | |
31 | my $name = prompt 'Contest name'; | |
32 | my $owner = prompt 'Owner'; | |
33 | my $start = str2time prompt 'Start time' or die 'Cannot parse time'; | |
34 | my $end = str2time prompt 'End time' or die 'Cannot parse time'; | |
35 | ||
36 | insert_contest $id => name => $name, owner => $owner, start => $start, end => $end; | |
37 | PUBLISH genpage => "ct/$id/index.html"; | |
38 | PUBLISH genpage => "ct/index.html"; | |
39 | } | |
40 | ||
41 | sub cmd_rm{ | |
42 | remove_contest shift; | |
43 | PUBLISH genpage => "ct/index.html"; | |
44 | } | |
45 | ||
46 | ################################################## | |
47 | ||
48 | no strict 'refs'; | |
49 | my $cmd = 'cmd_' . shift; | |
50 | cmd_help unless exists $main::{$cmd}; | |
51 | $cmd->(@ARGV) if exists $main::{$cmd}; | |
52 | ||
53 | 1; | |
54 | __END__ | |
55 | ||
56 | =encoding utf-8 | |
57 | ||
58 | =head1 NAME | |
59 | ||
60 | gruntmaster-contest - shell interface to Gruntmaster 6000 contests | |
61 | ||
62 | =head1 SYNOPSIS | |
63 | ||
64 | gruntmaster-contest list | |
65 | gruntmaster-contest show id | |
66 | gruntmaster-contest add id | |
67 | gruntmaster-contest rm id | |
68 | ||
69 | =head1 DESCRIPTION | |
70 | ||
e90402be MG |
71 | gruntmaster-contest is a tool for managing contests. |
72 | ||
73 | =over | |
74 | ||
75 | =item B<list> | |
76 | ||
77 | Prints the list of contests. | |
78 | ||
79 | =item B<show> I<id> | |
80 | ||
81 | Prints detailed information about the contest with id I<id>. | |
82 | ||
83 | =item B<add> I<id> | |
84 | ||
85 | Adds a new contest with id I<id>. | |
86 | ||
87 | =item B<rm> I<id> | |
88 | ||
89 | Removes the contest with id I<id> | |
90 | ||
91 | =back | |
92 | ||
93 | =head1 AUTHOR | |
94 | ||
95 | Marius Gavrilescu E<lt>marius@ieval.roE<gt> | |
96 | ||
97 | =head1 COPYRIGHT AND LICENSE | |
98 | ||
99 | Copyright (C) 2014 by Marius Gavrilescu | |
100 | ||
101 | This library is free software: you can redistribute it and/or modify | |
102 | it under the terms of the GNU Affero General Public License as published by | |
103 | the Free Software Foundation, either version 3 of the License, or | |
104 | (at your option) any later version. | |
014ee8a6 MG |
105 | |
106 | ||
107 | =cut |