-
Notifications
You must be signed in to change notification settings - Fork 20
/
features
executable file
·62 lines (47 loc) · 1.58 KB
/
features
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
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use JSON::PP;
use File::Slurp;
use List::MoreUtils qw( uniq );
use Template;
# Active columns defined in template
my @TOOLS = qw( ack ag git gnu rg );
my %TOOLS = map { $_ => 1 } @TOOLS;
# Additional tool values collected, valid, but to be ignored ...
# TODO: ... until refactor to render Grep-variant-suffixes in grep column
my @grep_variants = qw( bsd freebsd netbsd osx posix );
@TOOLS{@grep_variants} = ((0) x scalar @grep_variants);
my $json_text = File::Slurp::read_file( 'features.json' );
my $sections = JSON::PP->new->utf8->decode($json_text);
for my $section ( @{$sections} ) {
my $heading = $section->{heading};
my $abilities = $section->{abilities};
for my $ability ( @{$abilities} ) {
my %flags_by_tool;
while ( my ($key,$value) = each %{$ability->{how}} ) {
for my $tool ( split( /\s*,\s*/, $key ) ) {
defined($TOOLS{$tool}) or die "Invalid tool '$tool' in key '$key'";
if ( $TOOLS{$tool} ) {
$flags_by_tool{$tool} = $value;
}
}
}
if ( !%flags_by_tool ) {
$ability->{how} = undef;
next;
}
my @distinct_flags = uniq values %flags_by_tool;
my @new_hows = map { $flags_by_tool{$_} // '' } @TOOLS;
$ability->{how} = \@new_hows;
}
}
my $vars = {
sections => $sections,
};
my %tt_settings = (
INCLUDE_PATH => [ qw( . tt tt/wrapper ) ],
);
my $tt = Template->new( \%tt_settings );
$tt->process( 'features.ttml', $vars ) or die $tt->error;