From 5ab4d79a705c818ee7da590032dba4bb751face9 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Fri, 2 Jul 2021 14:50:21 -0700 Subject: [PATCH] projtool.pl: add verify command Provide a verify command in much the same vein as Git's `git rev-parse --verify` invocation. When given a project name or path, resolve that to the actual project, verify that it exists and can be loaded and then show its canonical project name on standard out and exit with success. Otherwise exit with an error code. Diagnostic messages are shown on standard error unless `--quiet` has been used. The verify command provides a convenient way to take advantage of the path-to-project translation facility from the command line. Signed-off-by: Kyle J. McKay --- toolbox/projtool.pl | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/toolbox/projtool.pl b/toolbox/projtool.pl index 09bfb58..3892c0c 100755 --- a/toolbox/projtool.pl +++ b/toolbox/projtool.pl @@ -10,7 +10,7 @@ use strict; use warnings; use vars qw($VERSION); -BEGIN {*VERSION = \'1.0.3'} +BEGIN {*VERSION = \'1.0.4'} use File::Basename; use Digest::MD5 qw(md5_hex); use IO::Socket; @@ -109,6 +109,12 @@ Usage: %s [...] show show project + verify [--quiet] + show the canonical project name for (which might + be a path) if and only if it exists. Otherwise display an + error (unless --quiet is used). Exit status will be 0 if + project found, non-zero otherwise. + urls [--push] show available fetch/push URLs for Note that this does NOT include non-Git protocol URLs such @@ -1214,6 +1220,25 @@ sub cmd_show { return 0; } +sub cmd_verify { + use Scalar::Util (); + my $rt = sub { return ref($_[0]) ? Scalar::Util::reftype($_[0]) : '' }; + parse_options("quiet" => \$quiet); + @ARGV == 1 or die_usage; + my $project = undef; + my $pname = undef; + eval { + $project = get_project_harder($ARGV[0]); + }; + $pname = $project->{name} if &$rt($project) eq 'HASH'; + defined($pname) && $pname ne "" or $project = undef; + !$@ && &$rt($project) ne 'HASH' and $@ = "No such project: \"$ARGV[0]\"\n"; + warn $@ if $@ && !$quiet; + exit 1 if $@; + printf "%s\n", $pname; + return 0; +} + sub cmd_urls { my $pushonly; parse_options("push" => \$pushonly); @@ -2092,6 +2117,7 @@ BEGIN { delete => \&cmd_remove, prune => \&cmd_prune, show => \&cmd_show, + verify => \&cmd_verify, urls => \&cmd_urls, listheads => \&cmd_listheads, listtags => \&cmd_listtags, @@ -2162,6 +2188,7 @@ BEGIN { %nopager = ( setusers => -1, set => -1, urls => -1, + verify => 1, )} sub dohelp { -- 2.11.4.GIT