-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
216 lines (191 loc) · 7.18 KB
/
Copy pathProgram.cs
File metadata and controls
216 lines (191 loc) · 7.18 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
using DotfilesManager.Core;
using DotfilesManager.Operations;
using DotfilesManager.UI;
namespace DotfilesManager;
internal static class Program
{
public static void Main(string[] args)
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Env.LoadOrInit();
// Watcher para recargar DotfilesDir si cambia config.json
using var watcher = new FileSystemWatcher(
Path.GetDirectoryName(Env.ConfigFile)!,
Path.GetFileName(Env.ConfigFile))
{
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime,
EnableRaisingEvents = true
};
watcher.Changed += (_, _) =>
{
Thread.Sleep(50); // Pequeña pausa para que termine de escribirse
Env.ReloadConfig();
Printer.Info($"DotfilesDir actualizado a: {Env.DotfilesDir}");
};
if (args.Length == 0)
{
Env.CliMode = 0;
RunInteractive();
}
else
{
Env.CliMode = 1;
RunCli(ArgParser.Parse(args));
}
}
private static void RunInteractive()
{
while (true)
{
string[] options = ["Symlinks", "Ejecutar script", "Perfiles"];
int choice = Menu.SelectOne("Dotfiles Manager", options);
switch (choice)
{
case -1: Console.WriteLine(); return;
case 0:
Printer.color = Colors.Red;
SymlinksMenu();
Printer.color = Printer.defaultColor;
break;
case 1:
Printer.color = Colors.Yellow;
ExecuteOp.Run();
Printer.color = Printer.defaultColor;
break;
case 2:
Printer.color = Colors.Purple;
ProfilesMenu();
Printer.color = Printer.defaultColor;
break;
}
}
}
private static void RunCli(CliCommand cmd)
{
switch (cmd.Type)
{
case CommandType.Error:
Environment.ExitCode = 1;
break;
case CommandType.Help:
ArgParser.ShowHelp();
break;
case CommandType.Apply:
if (cmd.SystemPaths.Length > 0)
ApplyOp.ApplySystem(cmd.SystemPaths);
else if (cmd.Packages.Length > 0)
ApplyOp.ApplyHome(cmd.Packages);
break;
case CommandType.Add:
if (cmd.AddToSystem && cmd.SystemPaths.Length > 0)
AddOp.AddToSystem(cmd.SystemPaths[0]);
else if (cmd.AddHomePath is not null && cmd.AddHomePackage is not null)
AddOp.AddToHome(cmd.AddHomePath, cmd.AddHomePackage);
break;
case CommandType.Backup:
if (cmd.BackupTarget == BackupTarget.Packages)
{
if (cmd.BackupAll)
Backup.BackupAllRepoPackages(Env.BackupDir + "_manualPackagesAllAction");
else
Backup.BackupRepoPackages(cmd.Packages, Env.BackupDir + "_manualPackagesAction");
}
else if (cmd.BackupTarget == BackupTarget.System)
{
if (cmd.BackupAll)
Backup.BackupAllRepoSystem(Env.BackupDir + "_manualSystemAllAction");
else
Backup.BackupRepoSystemPaths(cmd.SystemPaths, Env.BackupDir + "_manualSystemAction");
}
break;
case CommandType.Delete:
if (cmd.DeleteSystem && cmd.SystemPaths.Length > 0)
DeleteOp.DeleteSystem(cmd.SystemPaths, cmd.Action!);
else if (cmd.Packages.Length > 0)
DeleteOp.DeleteHome(cmd.Packages[0], cmd.Action!);
break;
case CommandType.Status:
StatusOp.Check();
break;
case CommandType.Script:
ExecuteOp.RunScript(cmd.ScriptName!, cmd.ScriptArgs);
break;
case CommandType.Profile:
switch (cmd.ProfileAction)
{
case ProfileAction.Create:
CreateProfileOp.Create(cmd.Profile!, cmd.Packages, cmd.Dotfiles);
break;
case ProfileAction.EditName:
EditProfileOp.EditName(cmd.Profile!, cmd.NewName!);
break;
case ProfileAction.EditPackages:
EditProfileOp.EditPackages(cmd.Profile!, cmd.Packages);
break;
case ProfileAction.EditDotfiles:
EditProfileOp.EditDotfiles(cmd.Profile!, cmd.Dotfiles);
break;
case ProfileAction.Apply:
ApplyProfileOp.ApplyProfile(cmd.Profile!, startStep: cmd.StartStep);
break;
case ProfileAction.Export:
ExportProfileOp.Export(cmd.Profile!);
break;
}
break;
case CommandType.SetDir:
Env.SetDotfilesDir(cmd.DotfilesDir!);
break;
}
}
// ── Menú de Symlinks ──────────────────────────────────────────────────
private static void SymlinksMenu()
{
string[] options =
[
"Aplicar / instalar dotfiles",
"Ver estado de symlinks",
"Borrar symlinks",
"Agregar archivo al repo",
];
bool running = true;
while (running)
{
int choice = Menu.SelectOne("Symlinks Manager", options);
switch (choice)
{
case -1: running = false; break;
case 0: ApplyOp.Run(); break;
case 1: StatusOp.Run(); break;
case 2: DeleteOp.Run(); break;
case 3: AddOp.Run(); break;
}
}
}
// ── Menú de Perfiles ──────────────────────────────────────────────────
private static void ProfilesMenu()
{
string[] options =
[
"Crear perfil",
"Editar perfil",
"Aplicar perfil",
"Exportar perfil",
];
bool running = true;
while (running)
{
Printer.color = Colors.Purple;
int choice = Menu.SelectOne("Perfiles", options);
switch (choice)
{
case -1: running = false; break;
case 0: CreateProfileOp.Run(); break;
case 1: EditProfileOp.Run(); break;
case 2: ApplyProfileOp.Run(); break;
case 3: ExportProfileOp.Run(); break;
}
Printer.color = Printer.defaultColor;
}
}
}