From: Tristan Partin <tristan@neon.tech>
To: pgsql-hackers@postgresql.org
Subject: Add --check option to pgindent
Date: Mon, 11 Dec 2023 18:09:21 -0600
Message-ID: <CXLX2XYTH9S6.140SC6Y61VD88@neon.tech> (raw)
Not sold on the name, but --check is a combination of --silent-diff and
--show-diff. I envision --check mostly being used in CI environments.
I recently came across a situation where this behavior would have been
useful. Without --check, you're left to capture the output of
--show-diff and exit 2 if the output isn't empty by yourself.
--
Tristan Partin
Neon (https://neon.tech)
Attachments:v1-0001-Add-check-option-to-pgindent.patch (text/x-patch, 2.3K) download
From 1001252d49a47e660045cee3d2ba5abd87e925d9 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Mon, 11 Dec 2023 17:34:17 -0600
Subject: [PATCH v1] Add --check option to pgindent
The option is a combination of --show-diff and --silent-diff. It is
useful for situations such as CI checks where the diff can be logged,
but will also cause the build to fail. Without such an option, people
are left to re-implement the same logic over and over again.
---
src/tools/pgindent/pgindent | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/src/tools/pgindent/pgindent b/src/tools/pgindent/pgindentindex bce63d95da..a285015c76 100755--- a/src/tools/pgindent/pgindent+++ b/src/tools/pgindent/pgindent@@ -23,7 +23,8 @@ my $devnull = File::Spec->devnull;
my ($typedefs_file, $typedef_str, @excludes,
$indent, $build, $show_diff,
- $silent_diff, $help, @commits,);+ $silent_diff, $help, @commits,+ $check,);
$help = 0;
@@ -35,7 +36,8 @@ my %options = (
"excludes=s" => \@excludes,
"indent=s" => \$indent,
"show-diff" => \$show_diff,
- "silent-diff" => \$silent_diff,);+ "silent-diff" => \$silent_diff,+ "check" => \$check,);
GetOptions(%options) || usage("bad command line argument");
usage() if $help;
@@ -43,6 +45,12 @@ usage() if $help;
usage("Cannot have both --silent-diff and --show-diff")
if $silent_diff && $show_diff;
+usage("Cannot have both --check and --show-diff")+ if $check && $show_diff;++usage("Cannot have both --check and --silent-diff")+ if $check && $silent_diff;+
usage("Cannot use --commit with command line file list")
if (@commits && @ARGV);
@@ -325,6 +333,7 @@ Options:
--indent=PATH path to pg_bsd_indent program
--show-diff show the changes that would be made
--silent-diff exit with status 2 if any changes would be made
+ --check combination of --show-diff and --silent-diff
The --excludes and --commit options can be given more than once.
EOF
if ($help)
@@ -417,7 +426,12 @@ foreach my $source_filename (@files)
if ($source ne $orig_source)
{
- if ($silent_diff)+ if ($check)+ {+ print show_diff($source, $source_filename);+ exit 2;+ }+ elsif ($silent_diff)
{
exit 2;
}
--
Tristan Partin
Neon (https://neon.tech)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tristan@neon.tech
Subject: Re: Add --check option to pgindent
In-Reply-To: <CXLX2XYTH9S6.140SC6Y61VD88@neon.tech>
References: <CXLX2XYTH9S6.140SC6Y61VD88@neon.tech>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox