Skip to content

Commit

Permalink
Support for markdown output in help messages
Browse files Browse the repository at this point in the history
This functionality can be used to provide on-line versions of the help
messages for alire.ada.dev.

It goes with alire-project/clic#29
  • Loading branch information
mgrojo committed Sep 20, 2023
1 parent 2e3a520 commit 6dd4546
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
15 changes: 14 additions & 1 deletion src/alr/alr-commands.adb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ package body Alr.Commands is
No_TTY : aliased Boolean := False;
-- Used to disable control characters in output

Markdown_Help : aliased Boolean := False;
-- Used to enable help display in markdown format

Version_Only : aliased Boolean := False;
-- Just display the current version and exit

Expand Down Expand Up @@ -157,6 +160,12 @@ package body Alr.Commands is
Long_Switch => "--no-tty",
Help => "Disables control characters in output");

Define_Switch (Config,
Markdown_Help'Access,
Long_Switch => "--markdown",
Help =>
"Enables output of markdown format for help");

Define_Switch (Config,
Prefer_Oldest'Access,
Long_Switch => "--prefer-oldest",
Expand Down Expand Up @@ -452,7 +461,11 @@ package body Alr.Commands is
end if;

if No_TTY then
CLIC.TTY.Force_Disable_TTY;
CLIC.Formatter.Force_Disable_TTY;
end if;

if Markdown_Help then
CLIC.Formatter.Enable_Markdown;
end if;

-- Use CLIC.TTY selection/detection of TTY
Expand Down
11 changes: 6 additions & 5 deletions src/alr/alr-commands.ads
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ with Alire.Solver;
with Alire.Version;

with CLIC.Subcommand;
with CLIC.Formatter;

private with GNAT.IO;
private with CLIC.Subcommand.Instance;
Expand Down Expand Up @@ -143,11 +144,11 @@ private
Put_Error => Put_Error,
Error_Exit => OS_Lib.Bailout,
Set_Global_Switches => Set_Global_Switches,
TTY_Chapter => Alire.TTY.Bold,
TTY_Description => Alire.TTY.Description,
TTY_Version => Alire.TTY.Version,
TTY_Underline => Alire.TTY.Underline,
TTY_Emph => Alire.TTY.Emph);
TTY_Chapter => CLIC.Formatter.Chapter,
TTY_Description => CLIC.Formatter.Description,
TTY_Version => CLIC.Formatter.Version,
TTY_Underline => CLIC.Formatter.Underline,
TTY_Emph => CLIC.Formatter.Emph);

Unset : constant String := "unset";
-- Canary for when a string switch is given without value
Expand Down

0 comments on commit 6dd4546

Please sign in to comment.