-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathalr-commands.ads
152 lines (114 loc) · 5.11 KB
/
alr-commands.ads
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
with AAA.Strings;
with Alire.Directories;
with Alire.Roots.Optional;
with Alire.Solver;
with Alire.Version;
with CLIC.Subcommand;
private with Ada.Text_IO;
private with CLIC.Subcommand.Instance;
private with Alr.OS_Lib; -- For the benefit of many child packages that use it
package Alr.Commands is
Wrong_Command_Arguments : exception;
-------------
-- Execute --
-------------
procedure Execute;
-- Entry point into alr, will parse the command line and proceed as needed.
-------------
-- Command --
-------------
type Command
is abstract limited new CLIC.Subcommand.Command
with private;
-- This type encapsulates configuration and execution of a specific
-- command.
overriding
function Switch_Parsing (This : Command)
return CLIC.Subcommand.Switch_Parsing_Kind
is (CLIC.Subcommand.Parse_All);
-- Default for alr commands is to parse the switches
-----------------------------------------
-- Supporting subprograms for commands --
-----------------------------------------
function Root (Cmd : in out Command'Class)
return Alire.Roots.Optional.Reference;
-- Using this call will ensure the Root detection has been attempted
procedure Set (Cmd : in out Command'Class;
Root : Alire.Roots.Root);
-- Replace the current root in use by the command. Modifying the root via
-- the Cmd.Root reference is valid and intended usage that does not require
-- resetting the root.
procedure Requires_Full_Index (Cmd : in out Command'Class;
Strict : Boolean := False;
Force_Reload : Boolean := False);
-- Unless Force_Reload, if the index is not empty we no nothing. When
-- strict, don't allow unknown values in enums.
procedure Requires_Workspace (Cmd : in out Command'Class;
Sync : Boolean := True;
Error : String := "");
-- Verifies that a valid workspace is in scope. After calling it,
-- Cmd.Root will be usable if alr was run inside a Root. If Sync, enforce
-- that the manifest, lockfile and dependencies on disk are in sync, by
-- performing a silent update. If not Sync, only a minimal empty lockfile
-- is created. If Error, replace the first generic error message with it.
function Has_Root (Cmd : in out Command'Class) return Boolean;
-- True when Requires_Workspace would succeed, false otherwise
procedure Load (Cmd : Command'Class;
Crate : Alire.Crate_Name;
Externals : Boolean := False;
Strict : Boolean := False);
-- Load a specific crate from the index. Optionally detect externals and
-- enforce no unknown enum index values.
---------------------------
-- command-line helpers --
---------------------------
function Is_Quiet return Boolean;
-- Says if -q was in the command line
function Query_Policy return Alire.Solver.Age_Policies;
-- Current policy
-- Declared here so they are available to the help metacommand child
-- package and Spawn.
function Crate_Version_Sets return AAA.Strings.Vector;
-- Returns the instructions to restrict version sets, for use in
-- Long_Description help functions.
function Enter_Workspace_Root return Alire.Directories.Destination;
-- Attempt to find the root alire workspace if deeper inside it
private
type Command
is abstract limited new CLIC.Subcommand.Command
with record
Optional_Root : Alire.Roots.Optional.Root;
end record;
-- Facilities for command/argument identification. These are available to
-- commands.
procedure Reportaise_Command_Failed (Message : String);
procedure Reportaise_Wrong_Arguments (Message : String);
-- Report and Raise :P
-- Folder guards conveniences for commands:
subtype Folder_Guard is Alire.Directories.Guard;
function Enter_Folder (Path : String) return Alire.Directories.Destination
renames Alire.Directories.Enter;
-- Common generalities
procedure New_Line (Spacing : Ada.Text_IO.Positive_Count := 1)
renames Ada.Text_IO.New_Line;
procedure Put_Line (S : String)
renames Ada.Text_IO.Put_Line;
procedure Put_Error (Str : String);
procedure Set_Global_Switches
(Config : in out CLIC.Subcommand.Switches_Configuration);
package Sub_Cmd is new CLIC.Subcommand.Instance
(Main_Command_Name => "alr",
Version => Alire.Version.Current,
Put => Ada.Text_IO.Put,
Put_Line => Ada.Text_IO.Put_Line,
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);
Unset : constant String := "unset";
-- Canary for when a string switch is given without value
end Alr.Commands;