Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON, TOML output for tables #1759

Merged
merged 6 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,6 @@
[submodule "deps/cstrings"]
path = deps/cstrings
url = https://github.com/mosteo/cstrings
[submodule "deps/lml"]
path = deps/lml
url = https://github.com/mosteo/lml_ada.git
1 change: 1 addition & 0 deletions alire.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ with "den";
with "dirty_booleans";
with "diskflags";
with "gnatcoll";
with "lml";
with "minirest";
with "optional";
with "semantic_versioning";
Expand Down
18 changes: 15 additions & 3 deletions alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ executables = ["alr"]
aaa = "~0.3.0"
ada_toml = "~0.3"
ajunitgen = "^1.0.1"
ansiada = "^1.0"
ansiada = "^1.1"
c_strings = "^1.0"
clic = "~0.3"
den = "~0.1"
dirty_booleans = "~0.1"
diskflags = "~0.1"
gnatcoll = "^21"
lml = "~0.1"
minirest = "~0.3"
optional = "~0.1"
semantic_versioning = "^3.0"
Expand All @@ -50,23 +51,30 @@ windows = { ALIRE_OS = "windows" }

# Some dependencies require precise versions during the development cycle:
[[pins]]

[pins.aaa]
url = "https://github.com/mosteo/aaa"
commit = "0c3b440ac183c450345d4a67d407785678779aae"
commit = "ddfeffe2d6c8f9d19161df7b31d16d37bef4ba71"

[pins.ada_toml]
url = "https://github.com/mosteo/ada-toml"
commit = "da4e59c382ceb0de6733d571ecbab7ea4919b33d"

[pins.ansiada]
url = "https://github.com/mosteo/ansi-ada"
commit = "0772e48d3e1f640829d142745a36b37edcd5470b"

[pins.c_strings]
url = "https://github.com/mosteo/cstrings"
commit = "e4d58ad90bf32bc44304197e5906a519f5a9a7bf"

[pins.clic]
url = "https://github.com/alire-project/clic"
commit = "56bbdc008e16996b6f76e443fd0165a240de1b13"

[pins.den]
url = "https://github.com/mosteo/den"
commit = "681ab5ca522585953f2e1d70763731df34c96012"
commit = "b12e8461bf41e2cfe199c8196b45fa4fc213a6aa"

[pins.dirty_booleans]
url = "https://github.com/mosteo/dirty_booleans"
Expand All @@ -80,6 +88,10 @@ commit = "60729edf31816aca0036b13b2794c39a9bd0172e"
url = "https://github.com/alire-project/gnatcoll-core.git"
commit = "4e663b87a028252e7e074f054f8f453661397166"

[pins.lml]
url = "https://github.com/mosteo/lml_ada.git"
commit = "ae156ef82a2fedb7e28bb4dcaeb3d5c0a2e046ec"

[pins.minirest]
url = "https://github.com/mosteo/minirest.git"
commit = "9a9c660f9c6f27f5ef75417e7fac7061dff14d78"
Expand Down
1 change: 1 addition & 0 deletions alr_env.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ aggregate project Alr_Env is
"deps/dirty_booleans",
"deps/diskflags",
"deps/gnatcoll-slim",
"deps/lml",
"deps/minirest",
"deps/optional",
"deps/semantic_versioning",
Expand Down
2 changes: 1 addition & 1 deletion deps/aaa
2 changes: 1 addition & 1 deletion deps/ansi
Submodule ansi updated 2 files
+1 −1 alire.toml
+32 −0 src/ansiada.ads
2 changes: 1 addition & 1 deletion deps/den
1 change: 1 addition & 0 deletions deps/lml
Submodule lml added at ae156e
7 changes: 6 additions & 1 deletion src/alire/alire-index-search.adb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ package body Alire.Index.Search is
Busy : Simple_Logging.Ongoing :=
Simple_Logging.Activity ("Searching");
begin
-- Preserve old behavior for human output
if Utils.Tables.Structured_Output then
Table.Header ("NAME").Header ("DESCRIPTION");
end if;

for Crate of Alire.Index.All_Crates.all loop
if Lookup = "" or else
Contains (To_Lower_Case (+Crate.Name), Lookup) or else
Expand All @@ -37,7 +42,7 @@ package body Alire.Index.Search is
Busy.Step;
end loop;

if Found = 0 then
if Found = 0 and then not Utils.Tables.Structured_Output then
Trace.Always ("No hits");
else
Table.Print (Always, Separator => " ");
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-solutions-diffs.adb
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ package body Alire.Solutions.Diffs is
end loop;

if Changed then
Table.Print (Level);
Table.Print (Level, Structured => False);

Warn_Toolchain_Download;
Warn_Unsatisfiable_GNAT_External;
Expand Down
11 changes: 10 additions & 1 deletion src/alire/alire-solutions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -923,8 +923,17 @@ package body Alire.Solutions is
Table : Utils.Tables.Table;
begin
if This.Links.Is_Empty and then Dependency_Map'(This.Pins).Is_Empty then
Trace.Always ("There are no pins");
if Utils.Tables.Structured_Output then
Table.Print (Always);
else
Trace.Always ("There are no pins");
end if;
else
-- To preserve old behavior with human output
if Utils.Tables.Structured_Output then
Table.Header ("Crate").Header ("Target").Header ("Origin").New_Row;
end if;

for Dep of This.Dependencies loop
if Dep.Is_Linked then
Table
Expand Down
6 changes: 3 additions & 3 deletions src/alire/alire-utils-did_you_mean.adb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ package body Alire.Utils.Did_You_Mean with Preelaborate is
for V in Enum loop
Possible_Values.Append
(case Transform is
when None => V'Img,
when None => V'Img,
when Lower_Case => AAA.Strings.To_Lower_Case (V'Img),
when Upper_Case => AAA.Strings.To_Lower_Case (V'Img),
when Tomify => TOML_Adapters.Tomify (V'Img));
when Upper_Case => AAA.Strings.To_Upper_Case (V'Img),
when Tomify => TOML_Adapters.Tomify (V'Img));
end loop;

return Suggestion (Input, Possible_Values);
Expand Down
37 changes: 27 additions & 10 deletions src/alire/alire-utils-tables.adb
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,39 @@ package body Alire.Utils.Tables is
-- Header --
------------

overriding
procedure Header (T : in out Table; Cell : String) is
Text : constant String :=
(if Structured_Output
then AAA.Strings.To_Lower_Case (Cell)
else TTY.Emph (AAA.Strings.To_Upper_Case (Cell)));
begin
T.Append (TTY.Emph (AAA.Strings.To_Upper_Case (Cell)));
Parent (T).Header (Text);
end Header;

------------
-- Header --
------------

overriding
function Header (T : aliased in out Table;
Cell : String)
return access Table is
return AAA.Table_IO.Reference
is
begin
T.Header (Cell);
return T'Access;
return AAA.Table_IO.Reference'(Table => T'Access);
end Header;

-----------
-- Print --
-----------

procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>))
procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>);
Structured : Boolean := Structured_Output)
is

procedure Print (Line : String) is
Expand All @@ -37,9 +49,14 @@ package body Alire.Utils.Tables is
end Print;

begin
T.Print (Separator => Separator,
Align => Align,
Put_Line => Print'Access);
if Structured then
T.Print (Structured_Output_Format,
Put_Line => Print'Access);
else
T.Print (Separator => Separator,
Align => Align,
Put_Line => Print'Access);
end if;
end Print;

end Alire.Utils.Tables;
30 changes: 22 additions & 8 deletions src/alire/alire-utils-tables.ads
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
with AAA.Table_IO;

package Alire.Utils.Tables with Preelaborate is
with LML;

type Table is new AAA.Table_IO.Table with null record;
package Alire.Utils.Tables is

subtype Formats is LML.Formats;

Structured_Output : Boolean := False;

Structured_Output_Format : Formats;

subtype Parent is AAA.Table_IO.Table;

type Table is new Parent with null record;

overriding
procedure Header (T : in out Table; Cell : String);

overriding
function Header (T : aliased in out Table;
Cell : String)
return access Table;
return AAA.Table_IO.Reference;

procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>));
-- Hook so tables use the default output facilities of Alire
procedure Print (T : Table;
Level : Trace.Levels := Info;
Separator : String := " ";
Align : AAA.Table_IO.Alignments := (1 .. 0 => <>);
Structured : Boolean := Structured_Output);
-- Hook so tables use the default output facilities of Alire. When
-- Structured_Output is enabled, formatting information is ignored.

end Alire.Utils.Tables;
16 changes: 7 additions & 9 deletions src/alr/alr-commands-index.adb
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
with AAA.Table_IO;

with Alire.Settings.Edit;
with Alire.Index;
with Alire.Index_On_Disk.Loading;
with Alire.Index_On_Disk.Updates;
with Alire.Utils;
with Alire.Utils.Tables;

package body Alr.Commands.Index is

Expand Down Expand Up @@ -155,18 +153,18 @@ package body Alr.Commands.Index is
Index_Load.Find_All
(Alire.Settings.Edit.Indexes_Directory, Result);

Table : AAA.Table_IO.Table;
Table : Alire.Utils.Tables.Table;
Count : Natural := 0;
begin
if not Result.Success then
Reportaise_Command_Failed (Alire.Message (Result));
end if;

Table
.Append (TTY.Emph ("#"))
.Append (TTY.Emph ("NAME"))
.Append (TTY.Emph ("URL"))
.Append (TTY.Emph ("PATH"));
.Header ("#")
.Header ("NAME")
.Header ("URL")
.Header ("PATH");

if Alire.Log_Level = Alire.Trace.Debug then
Table.Append (TTY.Emph ("PRIORITY"));
Expand All @@ -187,7 +185,7 @@ package body Alr.Commands.Index is
end loop;

if Count > 0 then
Table.Print;
Table.Print (Always);
else
Trace.Info ("No index configured.");
end if;
Expand Down
12 changes: 6 additions & 6 deletions src/alr/alr-commands-search.adb
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ package body Alr.Commands.Search is
-- End of option verification, start of search. First load the index,
-- required to look at its entries.

Tab.Append (TTY.Bold ("NAME"));
Tab.Append (TTY.Bold ("STATUS"));
Tab.Append (TTY.Bold ("VERSION"));
Tab.Append (TTY.Bold ("DESCRIPTION"));
Tab.Append (TTY.Bold ("NOTES"));
Tab.Append (TTY.Bold ("MATCHES"));
Tab.Header ("NAME");
Tab.Header ("STATUS");
Tab.Header ("VERSION");
Tab.Header ("DESCRIPTION");
Tab.Header ("NOTES");
Tab.Header ("MATCHES");

declare
Busy : Simple_Logging.Ongoing :=
Expand Down
18 changes: 9 additions & 9 deletions src/alr/alr-commands-toolchain.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

with AAA.Table_IO;

with Alire.Settings.Edit;
with Alire.Containers;
with Alire.Dependencies;
Expand All @@ -10,14 +8,16 @@ with Alire.Origins.Deployers;
with Alire.Releases.Containers;
with Alire.Solver;
with Alire.Toolchains;
with Alire.Utils; use Alire.Utils;
with Alire.Utils.Tables;
with Alire.Utils.TTY;
with Alire.Warnings;

with Semantic_Versioning.Extended;

package body Alr.Commands.Toolchain is

use Alire.Utils;

package Name_Sets renames Alire.Containers.Crate_Name_Sets;

--------------------
Expand Down Expand Up @@ -268,7 +268,7 @@ package body Alr.Commands.Toolchain is
pragma Unreferenced (Cmd);
use Alire;
use type Dependencies.Dependency;
Table : AAA.Table_IO.Table;
Table : Tables.Table;
begin
Alire.Toolchains.Detect_Externals;
-- Even if we have selected a non-external toolchain, in this case we
Expand All @@ -281,10 +281,10 @@ package body Alr.Commands.Toolchain is
end if;

Table
.Append (TTY.Emph ("CRATE"))
.Append (TTY.Emph ("VERSION"))
.Append (TTY.Emph ("STATUS"))
.Append (TTY.Emph ("NOTES"))
.Header ("CRATE")
.Header ("VERSION")
.Header ("STATUS")
.Header ("NOTES")
.New_Row;

for Dep of Alire.Toolchains.Available loop
Expand All @@ -311,7 +311,7 @@ package body Alr.Commands.Toolchain is
end if;
end loop;

Table.Print;
Table.Print (Always);
end List;

-------------
Expand Down
Loading
Loading