Skip to content

Commit

Permalink
New alr edit --select-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
mosteo committed Feb 24, 2024
1 parent a30e568 commit 0257b54
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/alr/alr-commands-edit.adb
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@ with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

package body Alr.Commands.Edit is

Switch_Select : constant String := "--select-editor";

--------------------
-- Set_Config_Cmd --
--------------------

procedure Set_Config_Cmd (Cmd : String) is
use Trace;
begin
Config.Set_Globally (Config.Builtins.Editor_Cmd, Cmd);
Put_Info ("'" & cmd & "' is now set as the editor command.");
if Cmd /= "" then
Config.Set_Globally (Config.Builtins.Editor_Cmd, Cmd);
Put_Info ("'" & TTY.Terminal (Cmd)
& "' is now set as the editor command.");
else
Config.Builtins.Editor_Cmd.Unset (Alire.Config.Global);
Put_Info ("The editor command has been unset.");
end if;

Put_Info ("You can change this setting by running the following command:");
Put_Info ("`alr config --global --unset " &
Config.Builtins.Editor_Cmd.Key & "`");
Put_Info ("and then run `alr edit` again.");
Put_Info ("`alr edit " & Switch_Select & "`");
end Set_Config_Cmd;

--------------------------
Expand Down Expand Up @@ -57,6 +64,8 @@ package body Alr.Commands.Edit is
use AAA.Strings;
use Clic.User_Input;

package Builtins renames Alire.Config.Builtins;

type Editor_Choice is (VScode, GNATstudio, Other);

subtype Editor_With_Command
Expand All @@ -76,6 +85,13 @@ package body Alr.Commands.Edit is

begin

if Builtins.Editor_Cmd.Is_Empty then
Put_Info ("There is no editor currently configured.");
else
Put_Info ("The current editor command is: '"
& TTY.Terminal (Builtins.Editor_Cmd.Get) & "'");
end if;

for Ed in Editor_Choice loop
Choices.Append (Img (Ed));
end loop;
Expand All @@ -96,6 +112,10 @@ package body Alr.Commands.Edit is
Set_Config_Cmd (Cmd (Answer));

when Other =>
Trace.Always
("In your custom editor command, `alr` will replace "
& TTY.Emph ("${GPR_FILE}")
& " with the corresponding project file.");
declare
Custom : constant String :=
Query_String ("Please enter a custom editor command",
Expand Down Expand Up @@ -165,6 +185,12 @@ package body Alr.Commands.Edit is
Reportaise_Wrong_Arguments (Cmd.Name & " doesn't take arguments");
end if;

-- Launch the editor selection if explicitly asked for
if Cmd.Set then
Query_Editor;
return;
end if;

-- Check if editor command is defined in the configuration
if Builtins.Editor_Cmd.Is_Empty then
Query_Editor;
Expand Down Expand Up @@ -251,6 +277,10 @@ package body Alr.Commands.Edit is
"", "--project=",
"Select the project file to open if the crate " &
"provides multiple project files, ignored otherwise");
Define_Switch (Config,
Cmd.Set'Access,
"", "--select-editor",
"Launch the interactive editor selector");
end Setup_Switches;

end Alr.Commands.Edit;
1 change: 1 addition & 0 deletions src/alr/alr-commands-edit.ads
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ private

type Command is new Commands.Command with record
Prj : aliased GNAT.Strings.String_Access;
Set : aliased Boolean; --select-editor
end record;
end Alr.Commands.Edit;

0 comments on commit 0257b54

Please sign in to comment.