1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#!/usr/bin/env perl
=head1 NAME
website - Website repository CLI manager.
=head1 SYNOPSIS
website <subcommand> [options]
Subcommands:
pastebin Create a new pastebin from the org-mode template.
slides Create a new HTML slideshow from the existing templates.
test Run internal CLI tests.
Options:
--help Show the manpage.
=head1 OPTIONS
=over 4
=item B<-h, --help>
Prints the manual page and exits.
=back
=head1 DESCRIPTION
B<website> is the top-level coordinator of subtasks inside the website repo.
=cut
use strict;
use warnings;
use Getopt::Long qw(:config no_ignore_case bundling pass_through);
use Pod::Usage qw(pod2usage);
use File::Basename qw(dirname);
use Term::ANSIColor;
my $help = 0;
my $title = '';
sub getopts {
GetOptions(
'help|h|?' => \$help
);
}
sub test {
print colored("FIXME", "red"), "\n";
}
sub escaped_cmd {
my ($cmd, @args) = @_;
my $dirname = dirname(__FILE__);
$cmd = "$dirname/$cmd";
$cmd = $cmd." \"$_\"", for @args;
system($cmd);
exit $? >> 8;
}
sub dispatch {
my $action = shift;
my @args = @_;
if (!defined $action && $help) {
pod2usage(
-verbose => 2,
-exitval => 0
);
} elsif (!defined $action) {
pod2usage(
-verbose => 1,
-exitval => 2,
-message => colored("Missing subcommand.", "red")
);
} elsif ($action eq 'pastebin') {
my @sub_args = grep { $_ ne $action } @args;
escaped_cmd("pastebin/website-pastebin", @sub_args);
} elsif ($action eq 'slides') {
my @sub_args = grep { $_ ne $action } @args;
escaped_cmd("slides/website-slides", @sub_args);
} elsif ($action eq 'test') {
test();
} else {
pod2usage(
-verbose => 1,
-exitval => 2,
-message => colored("Unknown subcommand: $action.", "red")
);
}
}
sub main {
my @orig_args=@ARGV;
getopts();
my $action=shift @ARGV;
dispatch($action, @orig_args);
}
main();
|