From 778ea2061b34f43129d98c203b47bc3844fb1f1f Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 12 Mar 2021 17:38:52 -0700 Subject: [PATCH] lint-all-readme.pl: allow running on specific projects only If one (or more) explicit project names are given, operate only on those projects rather than the entire list of known projects. Signed-off-by: Kyle J. McKay --- toolbox/lint-all-readme.pl | 60 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 49 insertions(+), 11 deletions(-) diff --git a/toolbox/lint-all-readme.pl b/toolbox/lint-all-readme.pl index a969af8..4eb9d17 100755 --- a/toolbox/lint-all-readme.pl +++ b/toolbox/lint-all-readme.pl @@ -11,8 +11,9 @@ use strict; use warnings; use vars qw($VERSION); -BEGIN {*VERSION = \'1.0.0'} +BEGIN {*VERSION = \'1.0.1'} use File::Basename qw(basename); +use Cwd qw(realpath); use lib "__BASEDIR__"; use Girocco::Config; use Girocco::Util; @@ -24,26 +25,62 @@ exit(&main(@ARGV)||0); our $help; BEGIN {$help = <<'HELP'} -Usage: %s [--help] [--dry-run] +Usage: %s [--help] [--dry-run] []... --help show this help - --dry-run show projects that need updating but don't update them + --dry-run show projects that need updating but don't update them -P/--progress show progress on STDERR (default if STDERR is a tty) + -q/--quiet suppress warning messages + + ... if given, only operate on these projects Exit status will always be non-zero if any readme files fail to lint. HELP sub lint_project_readmes { - my ($dryrun, $show_progress) = @_; + my $dryrun = shift; + my $show_progress = shift; + my $quiet = shift; my %allprojs = map({$_ => 1} Girocco::Project::get_full_list()); - my @allprojs = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%allprojs)); + my @projs = (); + if (@_) { + my $root = $Girocco::Config::reporoot; + $root =~ s,/+$,,; + $root ne "" or $root = "/"; + $root = realpath($root); + $root = $1 if $root =~ m|^(/.+)$|; + my %seen = (); + foreach (@_) { + exists($seen{$_}) and next; + if (!exists($allprojs{$_})) { + s,/+$,,; + $_ ne "" or $_ = "/"; + -d $_ and $_ = realpath($_); + s,^\Q$root\E/,,; + s,^/+,,; + $_ = $1 if $_ =~ m|^(.+)$|; + s,\.git$,,; + exists($seen{$_}) and next; + if (!exists($allprojs{$_})) { + $seen{$_} = 1; + warn "$_: unknown to Girocco (not in etc/group)\n" + unless $quiet; + next; + } + } + $seen{$_} = 1; + push(@projs, $_); + } + } else { + @projs = sort({lc($a) cmp lc($b) || $a cmp $b} keys(%allprojs)); + } my @outdated = (); my @badlint = (); my $bd = $Girocco::Config::reporoot . '/'; my $progress = Girocco::CLIUtil::Progress->new( - $show_progress ? scalar(@allprojs) : 0, + $show_progress ? scalar(@projs) : 0, "Checking project readme files"); my $cnt = 0; - foreach (@allprojs) { + foreach (@projs) { ++$cnt; $progress->update($cnt); my $pd = $bd . $_ . '.git'; @@ -76,7 +113,7 @@ sub lint_project_readmes { $progress->emit("$_: updated"); } } - return {count => scalar(@allprojs), outdated => \@outdated, + return {count => scalar(@projs), outdated => \@outdated, badlint => \@badlint}; } @@ -90,17 +127,18 @@ sub dohelp { sub main { local *ARGV = \@_; - my ($dryrun, $help); + my ($quiet, $dryrun, $help); my $progress = -t STDERR; { + shift, $quiet=1, redo if @ARGV && $ARGV[0] =~ /^(?:-q|--quiet)$/i; shift, $dryrun=1, redo if @ARGV && $ARGV[0] =~ /^(?:-n|--dry-run)$/i; shift, $help=1, redo if @ARGV && $ARGV[0] =~ /^(?:-h|--help)$/i; shift, $progress=1, redo if @ARGV && $ARGV[0] =~ /^(?:-P|--progress)$/i; shift, $progress=0, redo if @ARGV && $ARGV[0] =~ /^(?:--no-progress)$/i; } - !@ARGV && !$help or dohelp($help ? \*STDOUT : \*STDERR, !$help); + $help || (@ARGV && $ARGV[0] =~ /^-/) and dohelp($help ? \*STDOUT : \*STDERR, !$help); nice_me(18); - my $results = lint_project_readmes(!!$dryrun, $progress); + my $results = lint_project_readmes(!!$dryrun, $progress, $quiet, @ARGV); printf "Total: %d %s: %d Lintfail: %d\n", $results->{count}, $dryrun ? "Outdated" : "Updated", scalar(@{$results->{outdated}}), -- 2.11.4.GIT