]> git.donarmstrong.com Git - perltidy.git/commitdiff
catch ambiguous entries commands which exit early (c333)
authorSteve Hancock <perltidy@users.sourceforge.net>
Wed, 1 May 2024 16:32:16 +0000 (09:32 -0700)
committerSteve Hancock <perltidy@users.sourceforge.net>
Wed, 1 May 2024 16:32:16 +0000 (09:32 -0700)
lib/Perl/Tidy.pm

index 1a8cb975169ae319e2a80ef572eed39232e2d41d..fefca32c60627f9d0de293d633698a00da84d535 100644 (file)
@@ -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 };