From 46122d7ff21e005d70c2295f00a4c8169dfd3633 Mon Sep 17 00:00:00 2001 From: Vadim Godunko Date: Fri, 4 Oct 2024 13:31:55 +0400 Subject: [PATCH] Add support of `--version` command line switch. --- source/gnatdoc/gnatdoc-command_line.adb | 24 ++++++++++++++++++++++++ source/gnatdoc/gnatdoc-version.ads | 23 +++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 source/gnatdoc/gnatdoc-version.ads diff --git a/source/gnatdoc/gnatdoc-command_line.adb b/source/gnatdoc/gnatdoc-command_line.adb index e9d8c28..e5c2494 100644 --- a/source/gnatdoc/gnatdoc-command_line.adb +++ b/source/gnatdoc/gnatdoc-command_line.adb @@ -21,9 +21,13 @@ with VSS.Strings.Conversions; with GNATdoc.Comments.Options; with GNATdoc.Options; +with GNATdoc.Version; with GPR2.Options; with GPR2.Project.Registry.Exchange; +with VSS.Strings.Formatters; +with VSS.Strings.Formatters.Strings; +with VSS.Strings.Templates; package body GNATdoc.Command_Line is @@ -32,6 +36,11 @@ package body GNATdoc.Command_Line is Long_Name => "help", Description => "Display help information"); + Version_Option : constant VSS.Command_Line.Binary_Option := + (Short_Name => <>, + Long_Name => "version", + Description => "Display version"); + Backend_Option : constant VSS.Command_Line.Value_Option := (Short_Name => <>, Long_Name => "backend", @@ -121,6 +130,7 @@ package body GNATdoc.Command_Line is procedure Initialize is begin Parser.Add_Option (Help_Option); + Parser.Add_Option (Version_Option); Parser.Add_Option (Print_Gpr_Registry_Option); Parser.Add_Option (Style_Option); Parser.Add_Option (Backend_Option); @@ -173,6 +183,20 @@ package body GNATdoc.Command_Line is VSS.Command_Line.Report_Message (Parser.Help_Text); end if; + if Parser.Is_Specified (Version_Option) then + declare + Template : constant + VSS.Strings.Templates.Virtual_String_Template := + "GNATdoc {}"; + + begin + VSS.Command_Line.Report_Error + (Template.Format + (VSS.Strings.Formatters.Strings.Image + (GNATdoc.Version.Version_String))); + end; + end if; + -- Process `--print-gpr-registry` if specified if Parser.Is_Specified (Print_Gpr_Registry_Option) then diff --git a/source/gnatdoc/gnatdoc-version.ads b/source/gnatdoc/gnatdoc-version.ads new file mode 100644 index 0000000..193bb88 --- /dev/null +++ b/source/gnatdoc/gnatdoc-version.ads @@ -0,0 +1,23 @@ +------------------------------------------------------------------------------ +-- GNAT Documentation Generation Tool -- +-- -- +-- Copyright (C) 2024, AdaCore -- +-- -- +-- This 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- -- +-- ware Foundation; either version 3, or (at your option) any later ver- -- +-- sion. This software is distributed in the hope that it will be useful, -- +-- but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- -- +-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -- +-- License for more details. You should have received a copy of the GNU -- +-- General Public License distributed with this software; see file -- +-- COPYING3. If not, go to http://www.gnu.org/licenses for a complete copy -- +-- of the license. -- +------------------------------------------------------------------------------ + +package GNATdoc.Version is + + Version_String : VSS.Strings.Virtual_String := + "%VERSION% (%DATE%)"; + +end GNATdoc.Version;