|
1 | | --- File: modshells/src/main/modshells.adb |
2 | | - |
3 | | -with Shell_Manager; -- 1. Import the package |
4 | | --- ... other necessary packages (e.g., Ada.Strings.Unbounded) ... |
5 | | - |
6 | | -procedure Modshells is |
7 | | - |
8 | | - -- NOTE: This path would ideally be derived from environment variables |
9 | | - -- or configuration settings managed by your config_store package. |
10 | | - -- For this example, we use a placeholder path: |
11 | | - Modshell_Root_Path : constant String := |
12 | | - "~/.config/nushell/modshells"; |
13 | | - |
14 | | -begin |
15 | | - -- [Application Initialisation Logic] |
16 | | - |
17 | | - -- 2. Call the new idempotent directory creation function. |
18 | | - Shell_Manager.Create_Modshell_Directories( |
19 | | - Root_Path => Modshell_Root_Path |
20 | | - ); |
21 | | - |
22 | | - -- [Rest of the application logic] |
23 | | - |
24 | | -exception |
25 | | - when others => |
26 | | - -- Implement robust error handling (Dependability priority) |
27 | | - -- perhaps using your config_store or logging utilities here. |
28 | | - raise; |
29 | | -end Modshells; |
| 1 | +with Ada.Directories; |
| 2 | +with Ada.Text_IO; |
| 3 | +with Ada.IO_Exceptions; |
| 4 | +with Ada.Strings.Unbounded; |
| 5 | +with Config_Store; |
| 6 | +with Shell_Manager; |
| 7 | + |
| 8 | +-- Assuming shell_manager.ads defines Shell_Type, Shell_Status, Shell_Info, and Shell_List |
| 9 | +package body Shell_Manager is |
| 10 | + |
| 11 | + -- FIX: Ensure Ada.Directories is in the use clause for Separator visibility. |
| 12 | + -- Use clauses for visibility |
| 13 | + use Ada.Directories, Ada.Strings.Unbounded, Ada.Text_IO; |
| 14 | + |
| 15 | + -- Constant signature for Is_Modularized check |
| 16 | + MODULARIZED_SIGNATURE : constant String := "# MODSHELLS_START - DO NOT REMOVE THIS LINE"; |
| 17 | + |
| 18 | + -- FIX: Type must be constrained OR bounds must be given immediately. |
| 19 | + -- We define a generic type and rely on the constant definition to constrain it. |
| 20 | + type Directory_List_Type is array (Positive range <>) of String; |
| 21 | + Required_Subdirectories : constant Directory_List_Type := |
| 22 | + ("core", "tools", "misc", "os", "ui"); |
| 23 | + |
| 24 | + ---------------------------------------------------------------------- |
| 25 | + -- Helper function to join two path components correctly. |
| 26 | + ---------------------------------------------------------------------- |
| 27 | + function Join_Path (Base : in String; Name : in String) return String is |
| 28 | + Path_Separator : constant Character := Separator; -- Separator is now visible |
| 29 | + begin |
| 30 | + if Base'Length > 0 and then Base(Base'Last) /= Path_Separator then |
| 31 | + return Base & Path_Separator & Name; |
| 32 | + else |
| 33 | + return Base & Name; |
| 34 | + end if; |
| 35 | + end Join_Path; |
| 36 | + |
| 37 | + ---------------------------------------------------------------------- |
| 38 | + -- Idempotently creates the modular shell directories. |
| 39 | + ---------------------------------------------------------------------- |
| 40 | + procedure Create_Modshell_Directories (Root_Path : in String) is |
| 41 | + begin |
| 42 | + if not Exists(Root_Path) then |
| 43 | + begin |
| 44 | + Create_Directory(Root_Path); |
| 45 | + exception |
| 46 | + -- FIX: Qualify ambiguous exceptions |
| 47 | + when Ada.Directories.Name_Error | Ada.Directories.Use_Error => raise; |
| 48 | + end; |
| 49 | + end if; |
| 50 | + |
| 51 | + for Subdir_Name of Required_Subdirectories loop |
| 52 | + declare |
| 53 | + Full_Path : constant String := Join_Path(Root_Path, Subdir_Name); |
| 54 | + begin |
| 55 | + if not Exists(Full_Path) then |
| 56 | + Create_Directory(Full_Path); |
| 57 | + end if; |
| 58 | + exception |
| 59 | + -- FIX: Qualify ambiguous exceptions |
| 60 | + when Ada.Directories.Name_Error | Ada.Directories.Use_Error => raise; |
| 61 | + end; |
| 62 | + end loop; |
| 63 | + end Create_Modshell_Directories; |
| 64 | + |
| 65 | + ---------------------------------------------------------------------- |
| 66 | + -- Shell Detection Stub (v0.0 Alpha) |
| 67 | + ---------------------------------------------------------------------- |
| 68 | + function Detect_Shells return Shell_List is |
| 69 | + -- Assumes Shell_List is an unconstrained type defined in .ads. |
| 70 | + -- FIX: MUST constrain the array instance here. |
| 71 | + Shell_Array : Shell_List(1..3); |
| 72 | + begin |
| 73 | + Shell_Array(1).Name := Nushell; |
| 74 | + Shell_Array(1).Status := Installed; |
| 75 | + Shell_Array(2).Name := Bash; |
| 76 | + Shell_Array(2).Status := Installed; |
| 77 | + Shell_Array(3).Name := Zsh; |
| 78 | + Shell_Array(3).Status := Installed; |
| 79 | + return Shell_Array; |
| 80 | + end Detect_Shells; |
| 81 | + |
| 82 | + ---------------------------------------------------------------------- |
| 83 | + -- Converts Shell_Type enumeration to String. |
| 84 | + ---------------------------------------------------------------------- |
| 85 | + function To_String(Shell : Shell_Type) return String is |
| 86 | + begin |
| 87 | + case Shell is |
| 88 | + when Bash => return "bash"; |
| 89 | + when Dash => return "dash"; |
| 90 | + when Fish => return "fish"; |
| 91 | + when Ion => return "ion"; |
| 92 | + when Nushell => return "nushell"; |
| 93 | + when Tcsh => return "tcsh"; |
| 94 | + when Zsh => return "zsh"; |
| 95 | + when Oils => return "oils"; |
| 96 | + when Pwsh => return "pwsh"; |
| 97 | + when Ksh => return "ksh"; |
| 98 | + end case; |
| 99 | + end To_String; |
| 100 | + |
| 101 | + ---------------------------------------------------------------------- |
| 102 | + -- Idempotency Check (Checks if the config file already sources the structure). |
| 103 | + ---------------------------------------------------------------------- |
| 104 | + function Is_Modularized (Shell : Shell_Type) return Boolean is |
| 105 | + Config_File_Path : constant String := "/tmp/mock_config.txt"; |
| 106 | + File_Handle : File_Type; |
| 107 | + Line : String; |
| 108 | + Last : Natural; |
| 109 | + begin |
| 110 | + begin |
| 111 | + Open(File_Handle, In_File, Config_File_Path); |
| 112 | + exception |
| 113 | + -- FIX: Explicitly qualify Name_Error to resolve hiding ambiguity |
| 114 | + when Ada.IO_Exceptions.Name_Error => return False; |
| 115 | + when others => raise; |
| 116 | + end; |
| 117 | + |
| 118 | + while not End_Of_File(File_Handle) loop |
| 119 | + Get_Line(File_Handle, Line, Last); |
| 120 | + if Line(1..Last) = MODULARIZED_SIGNATURE(1..Last) then |
| 121 | + Close(File_Handle); |
| 122 | + return True; |
| 123 | + end if; |
| 124 | + end loop; |
| 125 | + |
| 126 | + Close(File_Handle); |
| 127 | + return False; |
| 128 | + end Is_Modularized; |
| 129 | + |
| 130 | + ---------------------------------------------------------------------- |
| 131 | + -- MISSING BODY FIX: Placeholder for Modularise_Config |
| 132 | + ---------------------------------------------------------------------- |
| 133 | + procedure Modularise_Config(Shell : Shell_Type) is |
| 134 | + -- Stub to satisfy the package specification |
| 135 | + begin |
| 136 | + -- The only statement: |
| 137 | + Ada.Text_IO.Put_Line("STUB: Modularising config for " & To_String(Shell)); |
| 138 | + end Modularise_Config; |
| 139 | +end Shell_Manager; |
0 commit comments