From ebecca565a76749d2440c55117e9799ce5109f67 Mon Sep 17 00:00:00 2001
From: Steve Hancock <perltidy@users.sourceforge.net>
Date: Wed, 1 May 2024 09:32:16 -0700
Subject: [PATCH] catch ambiguous entries commands which exit early (c333)

---
 lib/Perl/Tidy.pm | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/lib/Perl/Tidy.pm b/lib/Perl/Tidy.pm
index 1a8cb975..fefca32c 100644
--- a/lib/Perl/Tidy.pm
+++ b/lib/Perl/Tidy.pm
@@ -4529,6 +4529,19 @@ sub _process_command_line {
         }
     }
 
+    # The above commands processed before disambiguation and then Exited.  So
+    # we need to check below to see if the user entered something like
+    # '-dump-t' or '-he'. This will slip past here and not get processed.
+    my %early_exit_commands = (
+        'help'                      => 'h',
+        'version'                   => 'v',
+        'dump-defaults'             => 'ddf',
+        'dump-integer-option-range' => 'dior',
+        'dump-long-names'           => 'dln',
+        'dump-short-names'          => 'dsn',
+        'dump-token-types'          => 'dtt',
+    );
+
     if ( $saw_dump_profile && $saw_ignore_profile ) {
         Warn("No profile to dump because of -npro\n");
         Exit(1);
@@ -4684,6 +4697,16 @@ EOM
         Die("Error on command line; for help try 'perltidy -h'\n");
     }
 
+    # Catch ambiguous entries which should have exited above (c333)
+    foreach my $long_name ( keys %early_exit_commands ) {
+        if ( $Opts{$long_name} ) {
+            my $short_name = $early_exit_commands{$long_name};
+            Die(<<EOM);
+Ambigiguos entry; please enter '--$long_name' or '-$short_name'
+EOM
+        }
+    }
+
     # reset Getopt::Long configuration back to its previous value
     if ( defined($glc) ) {
         my $ok = eval { Getopt::Long::Configure($glc); 1 };
-- 
2.39.5