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.1'}
15 use File::Basename qw(basename);
17 use lib
"__BASEDIR__";
22 my $bn; BEGIN {$bn = basename
(__FILE__
)}
24 exit(&main
(@ARGV)||0);
27 BEGIN {$help = <<'HELP'}
28 Usage: %s [--help] [--dry-run] [<projname>]...
30 --dry-run show projects that need updating but don't update them
31 -P/--progress show progress on STDERR (default if STDERR is a tty)
32 -q/--quiet suppress warning messages
34 <projname>... if given, only operate on these projects
36 Exit status will always be non-zero if any readme files fail to lint.
39 sub lint_project_readmes
{
41 my $show_progress = shift;
43 my %allprojs = map({$_ => 1} Girocco
::Project
::get_full_list
());
46 my $root = $Girocco::Config
::reporoot
;
48 $root ne "" or $root = "/";
49 $root = realpath
($root);
50 $root = $1 if $root =~ m
|^(/.+)$|;
53 exists($seen{$_}) and next;
54 if (!exists($allprojs{$_})) {
57 -d
$_ and $_ = realpath
($_);
60 $_ = $1 if $_ =~ m
|^(.+)$|;
62 exists($seen{$_}) and next;
63 if (!exists($allprojs{$_})) {
65 warn "$_: unknown to Girocco (not in etc/group)\n"
74 @projs = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%allprojs));
78 my $bd = $Girocco::Config
::reporoot
. '/';
79 my $progress = Girocco
::CLIUtil
::Progress
->new(
80 $show_progress ?
scalar(@projs) : 0,
81 "Checking project readme files");
85 $progress->update($cnt);
86 my $pd = $bd . $_ . '.git';
87 -d
$pd or next; # just ignore any phantoms
89 eval { $proj = Girocco
::Project
->load($_); 1; } && $proj or
90 next; # just ignore unloadable projects
91 my $readme = $proj->{README
};
92 defined($readme) or $readme = "";
94 my ($cnt, $err) = $proj->_lint_readme(0);
97 $progress->emit("$_: error: $err");
100 my $newreadme = $proj->{README
};
101 defined($newreadme) or $newreadme = "";
103 $readme eq $newreadme and next;
106 $progress->emit("$_: needs update");
109 $proj->_property_fput("READMEDATA", $proj->{READMEDATA
}, 1);
110 $proj->_property_fput("README", $proj->{README
}, -e
"$pd/README.html");
111 $proj->_property_fput("rmtype", $proj->{rmtype
}, 1);
113 $progress->emit("$_: updated");
116 return {count
=> scalar(@projs), outdated
=> \
@outdated,
117 badlint
=> \
@badlint};
123 printf $fd "%s version %s\n", $bn, $VERSION;
124 printf $fd $help, $bn;
130 my ($quiet, $dryrun, $help);
131 my $progress = -t STDERR
;
133 shift, $quiet=1, redo if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i;
134 shift, $dryrun=1, redo if @ARGV && $ARGV[0] =~ /^(?:-n|--dry-run)$/i;
135 shift, $help=1, redo if @ARGV && $ARGV[0] =~ /^(?:-h|--help)$/i;
136 shift, $progress=1, redo if @ARGV && $ARGV[0] =~ /^(?:-P|--progress)$/i;
137 shift, $progress=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-progress)$/i;
139 $help || (@ARGV && $ARGV[0] =~ /^-/) and dohelp
($help ? \
*STDOUT
: \
*STDERR
, !$help);
141 my $results = lint_project_readmes
(!!$dryrun, $progress, $quiet, @ARGV);
142 printf "Total: %d %s: %d Lintfail: %d\n",
144 $dryrun ?
"Outdated" : "Updated", scalar(@
{$results->{outdated
}}),
145 scalar(@
{$results->{badlint
}});
146 exit @
{$results->{badlint
}} ?
1 : 0;