-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
158 lines (134 loc) · 5.71 KB
/
Program.cs
File metadata and controls
158 lines (134 loc) · 5.71 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
using System.Reflection;
using SharpConsoleUI;
using SharpConsoleUI.Configuration;
using SharpConsoleUI.Helpers;
using SharpConsoleUI.Drivers;
using LazyNuGet.Services;
namespace LazyNuGet;
class Program
{
static async Task<int> Main(string[] args)
{
// Handle --version / -v
if (args.Any(a => a == "--version" || a == "-v"))
{
var version = Assembly.GetExecutingAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion ?? "unknown";
Console.WriteLine($"lazynuget {version}");
return 0;
}
// Handle --help / -h
if (args.Any(a => a == "--help" || a == "-h"))
{
Console.WriteLine("Usage: lazynuget [path]");
Console.WriteLine(" lazynuget --migrate [path]");
Console.WriteLine(" lazynuget --migrate-cpm [path]");
Console.WriteLine();
Console.WriteLine(" path Folder to open (default: current directory)");
Console.WriteLine(" --migrate Migrate packages.config projects to PackageReference");
Console.WriteLine(" --migrate-cpm Migrate PackageReference projects to Central Package Management");
Console.WriteLine(" --version Show version information");
Console.WriteLine(" --help Show this help message");
return 0;
}
// Handle --migrate (headless, no UI)
if (args.Length > 0 && args[0] == "--migrate")
{
string targetPath = args.Length > 1
? Path.GetFullPath(args[1])
: Environment.CurrentDirectory;
if (!Directory.Exists(targetPath))
{
Console.Error.WriteLine($"Error: Directory '{targetPath}' does not exist.");
return 1;
}
var migrationService = new PackagesConfigMigrationService();
var results = await migrationService.MigrateAllInFolderAsync(
targetPath,
progress: new Progress<string>(Console.WriteLine));
foreach (var r in results)
{
if (r.Success)
Console.WriteLine($" ✓ {Path.GetFileName(r.ProjectPath)} — {r.PackagesMigrated} package(s) migrated");
else
Console.WriteLine($" ✗ {Path.GetFileName(r.ProjectPath)} — {r.Error}");
}
if (!results.Any())
Console.WriteLine("No packages.config projects found.");
return results.All(r => r.Success) ? 0 : 1;
}
// Handle --migrate-cpm (headless, no UI)
if (args.Length > 0 && args[0] == "--migrate-cpm")
{
string targetPath = args.Length > 1
? Path.GetFullPath(args[1])
: Environment.CurrentDirectory;
if (!Directory.Exists(targetPath))
{
Console.Error.WriteLine($"Error: Directory '{targetPath}' does not exist.");
return 1;
}
var svc = new CpmMigrationService();
var analysis = await svc.AnalyzeAsync(
targetPath, new Progress<string>(Console.WriteLine));
if (analysis.ProjectsToMigrate.Count == 0)
{
Console.WriteLine("No projects to migrate (all already use CPM or packages.config).");
return 0;
}
var result = await svc.MigrateAsync(
targetPath, analysis, new Progress<string>(Console.WriteLine));
if (result.Success)
Console.WriteLine(
$" ✓ {result.ProjectsMigrated} project(s) migrated, " +
$"{result.PackagesCentralized} package(s) centralized" +
(result.VersionConflictsResolved > 0
? $", {result.VersionConflictsResolved} conflict(s) resolved (highest version used)"
: string.Empty));
else
Console.WriteLine($" ✗ {result.Error}");
return result.Success ? 0 : 1;
}
var configService = new ConfigurationService();
var settings = configService.Load();
// Priority: CLI arg > current directory
// Note: LastFolderPath is tracked for UI history, not used as default
string folderPath = args.Length > 0
? args[0]
: Environment.CurrentDirectory;
// Resolve to absolute path to avoid issues with relative paths
folderPath = Path.GetFullPath(folderPath);
// Validate folder exists
if (!Directory.Exists(folderPath))
{
Console.Error.WriteLine($"Error: Directory '{folderPath}' does not exist.");
return 1;
}
try
{
var driverOptions = new NetConsoleDriverOptions
{
RenderMode = RenderMode.Buffer
};
var driver = new NetConsoleDriver(driverOptions);
var windowSystem = new ConsoleWindowSystem(
driver,
options: new ConsoleWindowSystemOptions(
ShowTopPanel: false,
ShowBottomPanel: false));
// Set default log level to Information
windowSystem.LogService.MinimumLevel = SharpConsoleUI.Logging.LogLevel.Information;
using var mainWindow = new LazyNuGetWindow(windowSystem, folderPath, configService);
mainWindow.Show();
await Task.Run(() => windowSystem.Run());
return 0;
}
catch (Exception ex)
{
Console.Clear();
ExceptionFormatter.WriteException(ex);
return 1;
}
}
}