-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
104 lines (89 loc) · 3.27 KB
/
Program.cs
File metadata and controls
104 lines (89 loc) · 3.27 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
using System.CommandLine;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using FeatherCli.Core.Commands;
using FeatherCli.Core.Configuration;
using FeatherCli.Core.Api;
using FeatherCli.Core.Api.Services;
using Spectre.Console;
// Check for version flag before parsing
if (args.Contains("--version") || args.Contains("-v"))
{
var version = Assembly.GetExecutingAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion ?? "1.1.3";
Console.WriteLine($"FeatherCli v{version}");
Console.WriteLine("Built with .NET 10.0");
Console.WriteLine("https://github.com/MythicalLTD/FeatherPanel");
return 0;
}
try
{
// Setup dependency injection
var services = new ServiceCollection();
// Configure logging based on verbose flag
var isVerbose = args.Contains("--verbose");
services.AddLogging(builder =>
{
builder.AddConsole();
if (isVerbose)
{
builder.SetMinimumLevel(LogLevel.Information);
// Keep HTTP logging for verbose mode
}
else
{
builder.SetMinimumLevel(LogLevel.Warning); // Only show warnings and errors by default
// Suppress HTTP client logging
builder.AddFilter("System.Net.Http.HttpClient", LogLevel.None);
builder.AddFilter("Microsoft.Extensions.Http", LogLevel.None);
}
});
// Add HTTP client
services.AddHttpClient<FeatherPanelApiClient>(client =>
{
client.Timeout = TimeSpan.FromSeconds(30);
});
// Add HTTP client for services
services.AddHttpClient();
// Add core services
services.AddSingleton<ConfigManager>();
services.AddSingleton<CommandRegistry>();
// Add API services
services.AddSingleton<ServerService>();
services.AddSingleton<PowerService>();
services.AddSingleton<LogService>();
services.AddSingleton<OAuth2Service>();
// Build service provider
var serviceProvider = services.BuildServiceProvider();
// Create command registry and root command
var commandRegistry = serviceProvider.GetRequiredService<CommandRegistry>();
var rootCommand = commandRegistry.CreateRootCommand();
// Add global options
var verboseOption = new Option<bool>("--verbose", "Enable verbose output");
rootCommand.AddGlobalOption(verboseOption);
// Add version command
var versionCommand = new Command("version", "Show version information");
versionCommand.SetHandler(() =>
{
var version = Assembly.GetExecutingAssembly()
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
.InformationalVersion ?? "1.1.3";
AnsiConsole.MarkupLine($"[bold blue]FeatherCli v{version}[/]");
AnsiConsole.MarkupLine("[dim]Built with .NET 9.0[/]");
AnsiConsole.MarkupLine("[dim]https://github.com/MythicalLTD/FeatherPanel[/]");
});
rootCommand.AddCommand(versionCommand);
// Run the command
return await rootCommand.InvokeAsync(args);
}
catch (Exception ex)
{
AnsiConsole.MarkupLine($"[red]✗ Unexpected error: {ex.Message}[/]");
if (args.Contains("--verbose"))
{
AnsiConsole.MarkupLine($"[red]Stack trace: {ex.StackTrace}[/]");
}
return 1;
}