11#nullable disable
22
33global using static Kantan . Diagnostics . LogCategories ;
4+ using Console = Spectre . Console . AnsiConsole ;
5+ using System . CommandLine ;
46using System . Diagnostics ;
57using System . Runtime . CompilerServices ;
68// using Windows.UI.Notifications;
79// using CommunityToolkit.WinUI.Notifications;
810using Novus ;
911using Terminal . Gui ;
10- using SmartImage . Shell ;
1112using SmartImage . App ;
13+ using SmartImage . Lib ;
14+ using SmartImage . Lib . Engines ;
15+ using SmartImage . Lib . Results ;
16+ using SmartImage . Utilities ;
17+ using Spectre . Console ;
18+ using Command = System . CommandLine . Command ;
1219
1320#pragma warning disable CS0168
1421
@@ -23,54 +30,83 @@ namespace SmartImage;
2330
2431public static class Program
2532{
26- private static ShellMain _main ;
2733
2834 [ ModuleInitializer ]
2935 public static void Init ( )
3036 {
3137 Global . Setup ( ) ;
3238 Trace . WriteLine ( "Init" , Resources . Name ) ;
3339 // Gui.Init();
34- Console . Title = R2 . Name ;
40+ System . Console . Title = R2 . Name ;
3541
3642 if ( Compat . IsWin ) {
3743 ConsoleUtil . SetConsoleMode ( ) ;
3844 }
3945
40- Application . Init ( ) ;
41-
4246 AppDomain . CurrentDomain . ProcessExit += ( sender , args ) =>
4347 {
4448 Trace . WriteLine ( $ "Exiting", R2 . Name ) ;
4549 } ;
4650 }
4751
48- public static async Task Main ( string [ ] args )
52+ public static async Task < int > Main ( string [ ] args )
4953 {
5054 // Console.OutputEncoding = Encoding.Unicode;
5155
5256 // ToastNotificationManagerCompat.OnActivated += AppNotification.OnActivated;
5357
5458#if TEST
5559 // args = new String[] { null };
56- args = new [ ] { R2 . Arg_Input , "https://i.imgur.com/QtCausw.png" , R2 . Arg_AutoSearch } ;
60+ // args = new[] { R2.Arg_Input, "https://i.imgur.com/QtCausw.png",R2.Arg_AutoSearch };
5761
5862 // ReSharper disable once ConditionIsAlwaysTrueOrFalse
63+
64+ Debug . WriteLine ( $ "TEST") ;
5965#endif
66+
6067 bool cli = args is { } && args . Any ( ) ;
6168
62- _main = new ShellMain ( args ) ;
69+ if ( cli && args . Contains ( Resources . Arg_NoUI ) ) {
70+
71+ var main = new CliMain ( ) ;
72+
73+ var rc = new RootCommand ( )
74+ { } ;
75+
76+ var arg = new Option < string > ( Resources . Arg_Input )
77+ { } ;
78+
79+ var opt2 = new Option < bool > ( Resources . Arg_NoUI )
80+ {
81+ Arity = ArgumentArity . Zero ,
82+
83+ } ;
84+
85+ rc . AddOption ( arg ) ;
86+ rc . AddOption ( opt2 ) ;
87+
88+ rc . SetHandler ( CliMain . RunCliAsync , arg ) ;
89+
90+ var i = await rc . InvokeAsync ( args ) ;
91+
92+ return i ;
93+ }
94+ else {
95+ main1 :
96+ Application . Init ( ) ;
6397
64- main1 :
98+ var main = new ShellMain ( args ) ;
99+ object status ;
65100
66- object status ;
101+ var run = main . RunAsync ( null ) ;
102+ status = await run ;
67103
68- var run = _main . RunAsync ( null ) ;
69- status = await run ;
104+ if ( status is bool { } and true ) {
105+ main . Dispose ( ) ;
106+ goto main1 ;
107+ }
70108
71- if ( status is bool { } and true ) {
72- _main . Dispose ( ) ;
73- goto main1 ;
109+ return 0 ;
74110 }
75111 }
76112}
0 commit comments