Copy Data.pm and gruntmaster tools from gruntmaster-page
[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 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
71
72
73 =cut
This page took 0.025705 seconds and 4 git commands to generate.