3 # lint-all-readme.pl - lint all projects' explicit README files
4 # Copyright (C) 2021 Kyle J. McKay.
6 # License GPLv2+: GNU GPL version 2 or later.
7 # www.gnu.org/licenses/gpl-2.0.html
8 # This is free software: you are free to change and redistribute it.
9 # There is NO WARRANTY, to the extent permitted by law.
13 use vars
qw($VERSION);
14 BEGIN {*VERSION = \'1.0.0'}
15 use File::Basename qw(basename);
16 use lib
"__BASEDIR__";
21 my $bn; BEGIN {$bn = basename
(__FILE__
)}
23 exit(&main
(@ARGV)||0);
26 BEGIN {$help = <<'HELP'}
27 Usage: %s [--help] [--dry-run]
29 --dry-run show projects that need updating but don't update them
30 -P/--progress show progress on STDERR (default if STDERR is a tty)
32 Exit status will always be non-zero if any readme files fail to lint.
35 sub lint_project_readmes
{
36 my ($dryrun, $show_progress) = @_;
37 my %allprojs = map({$_ => 1} Girocco
::Project
::get_full_list
());
38 my @allprojs = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%allprojs));
41 my $bd = $Girocco::Config
::reporoot
. '/';
42 my $progress = Girocco
::CLIUtil
::Progress
->new(
43 $show_progress ?
scalar(@allprojs) : 0,
44 "Checking project readme files");
48 $progress->update($cnt);
49 my $pd = $bd . $_ . '.git';
50 -d
$pd or next; # just ignore any phantoms
52 eval { $proj = Girocco
::Project
->load($_); 1; } && $proj or
53 next; # just ignore unloadable projects
54 my $readme = $proj->{README
};
55 defined($readme) or $readme = "";
57 my ($cnt, $err) = $proj->_lint_readme(0);
60 $progress->emit("$_: error: $err");
63 my $newreadme = $proj->{README
};
64 defined($newreadme) or $newreadme = "";
66 $readme eq $newreadme and next;
69 $progress->emit("$_: needs update");
72 $proj->_property_fput("READMEDATA", $proj->{READMEDATA
}, 1);
73 $proj->_property_fput("README", $proj->{README
}, -e
"$pd/README.html");
74 $proj->_property_fput("rmtype", $proj->{rmtype
}, 1);
76 $progress->emit("$_: updated");
79 return {count
=> scalar(@allprojs), outdated
=> \
@outdated,
80 badlint
=> \
@badlint};
86 printf $fd "%s version %s\n", $bn, $VERSION;
87 printf $fd $help, $bn;
94 my $progress = -t STDERR
;
96 shift, $dryrun=1, redo if @ARGV && $ARGV[0] =~ /^(?:-n|--dry-run)$/i;
97 shift, $help=1, redo if @ARGV && $ARGV[0] =~ /^(?:-h|--help)$/i;
98 shift, $progress=1, redo if @ARGV && $ARGV[0] =~ /^(?:-P|--progress)$/i;
99 shift, $progress=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-progress)$/i;
101 !@ARGV && !$help or dohelp
($help ? \
*STDOUT
: \
*STDERR
, !$help);
103 my $results = lint_project_readmes
(!!$dryrun, $progress);
104 printf "Total: %d %s: %d Lintfail: %d\n",
106 $dryrun ?
"Outdated" : "Updated", scalar(@
{$results->{outdated
}}),
107 scalar(@
{$results->{badlint
}});
108 exit @
{$results->{badlint
}} ?
1 : 0;