diff mbox

[Ada] No usage for an erroneous invocation of a gnat tool

Message ID 20140717061221.GA21157@adacore.com
State New
Headers show

Commit Message

Arnaud Charlet July 17, 2014, 6:12 a.m. UTC
When a gnat tool (gnatbind, gnatclean, gnatchop, gnatfind, gnatls,
gnatname, gnatprep or gnatmake) is incorrectly invoked, the usage is
no longer displayed. Instead, this line is displayed:

  type "gnatxxx --help" for help

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-07-17  Vincent Celier  <celier@adacore.com>

	* gnatchop.adb, make.adb, gnatbind.adb, clean.adb, gprep.adb,
	gnatxref.adb, gnatls.adb, gnatfind.adb, gnatname.adb: Do not output
	the usage for an erroneous invocation of a gnat tool.
diff mbox

Patch

Index: gnatchop.adb
===================================================================
--- gnatchop.adb	(revision 212640)
+++ gnatchop.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1998-2012, Free Software Foundation, Inc.         --
+--          Copyright (C) 1998-2014, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -1248,7 +1248,12 @@ 
       --  At least one filename must be given
 
       elsif File.Last = 0 then
-         Usage;
+         if Argument_Count = 0 then
+            Usage;
+         else
+            Put_Line ("type ""gnatchop --help"" for help");
+         end if;
+
          return False;
 
       --  No directory given, set directory to null, so that we can just
Index: make.adb
===================================================================
--- make.adb	(revision 212659)
+++ make.adb	(working copy)
@@ -5856,9 +5856,14 @@ 
 
             Targparm.Get_Target_Parameters;
 
-            --  Output usage information if no files to compile
+            --  Output usage information if no argument on the command line
 
-            Usage;
+            if Argument_Count = 0 then
+               Usage;
+            else
+               Write_Line ("type ""gnatmake --help"" for help");
+            end if;
+
             Finish_Program (Project_Tree, E_Success);
          end if;
       end if;
Index: gnatbind.adb
===================================================================
--- gnatbind.adb	(revision 212654)
+++ gnatbind.adb	(working copy)
@@ -666,10 +666,15 @@ 
       Display_Version ("GNATBIND", "1995");
    end if;
 
-   --  Output usage information if no files
+   --  Output usage information if no arguments
 
    if not More_Lib_Files then
-      Bindusg.Display;
+      if Argument_Count = 0 then
+         Bindusg.Display;
+      else
+         Write_Line ("type ""gnatbind --help"" for help");
+      end if;
+
       Exit_Program (E_Fatal);
    end if;
 
Index: clean.adb
===================================================================
--- clean.adb	(revision 212640)
+++ clean.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2003-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 2003-2014, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -1460,11 +1460,16 @@ 
          end;
       end if;
 
-      --  If neither a project file nor an executable were specified, output
-      --  the usage and exit.
+      --  If neither a project file nor an executable were specified, exit
+      --  displaying the usage if there were no arguments on the command line.
 
       if Main_Project = No_Project and then Osint.Number_Of_Files = 0 then
-         Usage;
+         if Argument_Count = 0 then
+            Usage;
+         else
+            Put_Line ("type ""gnatclean --help"" for help");
+         end if;
+
          return;
       end if;
 
Index: gprep.adb
===================================================================
--- gprep.adb	(revision 212640)
+++ gprep.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2002-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 2002-2014, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -38,7 +38,8 @@ 
 with Switch;   use Switch;
 with Types;    use Types;
 
-with Ada.Text_IO;     use Ada.Text_IO;
+with Ada.Command_Line; use Ada.Command_Line;
+with Ada.Text_IO;      use Ada.Text_IO;
 
 with GNAT.Case_Util;            use GNAT.Case_Util;
 with GNAT.Command_Line;
@@ -205,14 +206,19 @@ 
 
          --  No input file specified, just output the usage and exit
 
-         Usage;
+         if Argument_Count = 0 then
+            Usage;
+         else
+            Put_Line ("type ""gnatprep --help"" for help");
+         end if;
+
          return;
 
       elsif Outfile_Name = No_Name then
 
-         --  No output file specified, just output the usage and exit
+         --  No output file specified, exit
 
-         Usage;
+         Put_Line ("type ""gnatprep --help"" for help");
          return;
       end if;
 
@@ -767,7 +773,7 @@ 
             when GNAT.Command_Line.Invalid_Switch =>
                Write_Str ("Invalid Switch: -");
                Write_Line (GNAT.Command_Line.Full_Switch);
-               Usage;
+               Put_Line ("type ""gnatprep --help"" for help");
                OS_Exit (1);
          end;
       end loop;
Index: gnatxref.adb
===================================================================
--- gnatxref.adb	(revision 212640)
+++ gnatxref.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1998-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1998-2014, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -30,6 +30,7 @@ 
 with Xr_Tabls; use Xr_Tabls;
 with Xref_Lib; use Xref_Lib;
 
+with Ada.Command_Line;  use Ada.Command_Line;
 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
 with Ada.Text_IO;       use Ada.Text_IO;
 
@@ -209,7 +210,8 @@ 
                end if;
 
             when others =>
-               Write_Usage;
+               Put_Line ("type ""gnatxref --help"" for help");
+               raise Usage_Error;
          end case;
       end loop;
 
@@ -225,7 +227,8 @@ 
             if Ada.Strings.Fixed.Index (S, ":") /= 0 then
                Ada.Text_IO.Put_Line
                  ("Only file names are allowed on the command line");
-               Write_Usage;
+               Put_Line ("type ""gnatxref --help"" for help");
+               raise Usage_Error;
             end if;
 
             Add_Xref_File (S);
@@ -237,12 +240,14 @@ 
       when GNAT.Command_Line.Invalid_Switch =>
          Ada.Text_IO.Put_Line ("Invalid switch : "
                                & GNAT.Command_Line.Full_Switch);
-         Write_Usage;
+         Put_Line ("type ""gnatxref --help"" for help");
+         raise Usage_Error;
 
       when GNAT.Command_Line.Invalid_Parameter =>
          Ada.Text_IO.Put_Line ("Parameter missing for : "
                                & GNAT.Command_Line.Full_Switch);
-         Write_Usage;
+         Put_Line ("type ""gnatxref --help"" for help");
+         raise Usage_Error;
    end Parse_Cmd_Line;
 
    -----------
@@ -296,7 +301,12 @@ 
    Parse_Cmd_Line;
 
    if not Have_File then
-      Write_Usage;
+      if Argument_Count = 0 then
+         Write_Usage;
+      else
+         Put_Line ("type ""gnatxref --help"" for help");
+         raise Usage_Error;
+      end if;
    end if;
 
    Xr_Tabls.Set_Default_Match (True);
Index: gnatls.adb
===================================================================
--- gnatls.adb	(revision 212663)
+++ gnatls.adb	(working copy)
@@ -45,6 +45,8 @@ 
 with Targparm;    use Targparm;
 with Types;       use Types;
 
+with Ada.Command_Line; use Ada.Command_Line;
+
 with GNAT.Case_Util; use GNAT.Case_Util;
 
 procedure Gnatls is
@@ -1599,7 +1601,7 @@ 
       Set_Standard_Error;
       Write_Str ("Can't use -l with another switch");
       Write_Eol;
-      Usage;
+      Write_Line ("type ""gnatls --help"" for help");
       Exit_Program (E_Fatal);
    end if;
 
@@ -1748,7 +1750,11 @@ 
 
    if not More_Lib_Files then
       if not Print_Usage and then not Verbose_Mode then
-         Usage;
+         if Argument_Count = 0 then
+            Usage;
+         else
+            Write_Line ("type ""gnatls --help"" for help");
+         end if;
       end if;
 
       Exit_Program (E_Fatal);
Index: gnatfind.adb
===================================================================
--- gnatfind.adb	(revision 212640)
+++ gnatfind.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 1998-2011, Free Software Foundation, Inc.         --
+--          Copyright (C) 1998-2014, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -30,6 +30,7 @@ 
 with Xr_Tabls; use Xr_Tabls;
 with Xref_Lib; use Xref_Lib;
 
+with Ada.Command_Line;  use Ada.Command_Line;
 with Ada.Strings.Fixed; use Ada.Strings.Fixed;
 with Ada.Text_IO;       use Ada.Text_IO;
 
@@ -227,7 +228,8 @@ 
                end if;
 
             when others =>
-               Write_Usage;
+               Put_Line ("type ""gnatfind --help"" for help");
+               raise Usage_Error;
          end case;
       end loop;
 
@@ -266,16 +268,19 @@ 
       when GNAT.Command_Line.Invalid_Switch =>
          Ada.Text_IO.Put_Line ("Invalid switch : "
                                & GNAT.Command_Line.Full_Switch);
-         Write_Usage;
+         Put_Line ("type ""gnatfind --help"" for help");
+         raise Usage_Error;
 
       when GNAT.Command_Line.Invalid_Parameter =>
          Ada.Text_IO.Put_Line ("Parameter missing for : "
                                & GNAT.Command_Line.Full_Switch);
-         Write_Usage;
+         Put_Line ("type ""gnatfind --help"" for help");
+         raise Usage_Error;
 
       when Xref_Lib.Invalid_Argument =>
          Ada.Text_IO.Put_Line ("Invalid line or column in the pattern");
-         Write_Usage;
+         Put_Line ("type ""gnatfind --help"" for help");
+         raise Usage_Error;
    end Parse_Cmd_Line;
 
    -----------
@@ -344,7 +349,12 @@ 
    Parse_Cmd_Line;
 
    if not Have_Entity then
-      Write_Usage;
+      if Argument_Count = 0 then
+         Write_Usage;
+      else
+         Put_Line ("type ""gnatfind --help"" for help");
+         raise Usage_Error;
+      end if;
    end if;
 
    --  Special case to speed things up: if the user has a command line of the
@@ -372,7 +382,8 @@ 
       Ada.Text_IO.Put_Line ("Error: for type hierarchy output you must "
                             & "specify only one file.");
       Ada.Text_IO.New_Line;
-      Write_Usage;
+      Put_Line ("type ""gnatfind --help"" for help");
+      raise Usage_Error;
    end if;
 
    Search (Pattern, Local_Symbols, Wide_Search, Read_Only,
Index: gnatname.adb
===================================================================
--- gnatname.adb	(revision 212640)
+++ gnatname.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2001-2013, Free Software Foundation, Inc.         --
+--          Copyright (C) 2001-2014, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -289,7 +289,7 @@ 
                       Patterns.Last
                         (Arguments.Table (Arguments.Last).Foreign_Patterns) = 0
                   then
-                     Usage;
+                     Put_Line ("type ""gnatname --help"" for help");
                      return;
                   end if;
 
@@ -619,7 +619,12 @@ 
       and then
       Patterns.Last (Arguments.Table (Arguments.Last).Foreign_Patterns) = 0
    then
-      Usage;
+      if Argument_Count = 0 then
+         Usage;
+      else
+         Put_Line ("type ""gnatname --help"" for help");
+      end if;
+
       return;
    end if;