1- using Devlooped . Sponsors ;
1+ using System . Diagnostics . CodeAnalysis ;
2+ using Devlooped . Sponsors ;
23using GitCredentialManager ;
34using Microsoft . Extensions . Configuration ;
45using Microsoft . Extensions . DependencyInjection ;
56using OpenAI ;
7+ using Spectre . Console ;
68using Spectre . Console . Cli ;
79
810namespace Devlooped . OpenAI ;
@@ -13,12 +15,28 @@ public static class App
1315
1416 static App ( ) => Console . CancelKeyPress += ( s , e ) => shutdownCancellation . Cancel ( ) ;
1517
18+ /// <summary>
19+ /// Whether the CLI app is not interactive (i.e. part of a script run,
20+ /// running in CI, or in a non-interactive user session).
21+ /// </summary>
22+ public static bool IsNonInteractive => ! Environment . UserInteractive
23+ || Console . IsInputRedirected
24+ || Console . IsOutputRedirected ;
25+
1626 public static CommandApp Create ( ) => Create ( out _ ) ;
1727
18- public static CommandApp Create ( out IServiceProvider services )
28+ public static CommandApp Create ( [ NotNull ] out IServiceProvider services )
29+ => Create ( new ServiceCollection ( ) , out services ) ;
30+
31+ public static CommandApp Create ( IAnsiConsole console , [ NotNull ] out IServiceProvider services )
1932 {
20- var collection = new ServiceCollection ( ) ;
33+ var app = Create ( new ServiceCollection ( ) . AddSingleton ( console ) , out services ) ;
34+ app . Configure ( config => config . ConfigureConsole ( console ) ) ;
35+ return app ;
36+ }
2137
38+ static CommandApp Create ( IServiceCollection collection , [ NotNull ] out IServiceProvider services )
39+ {
2240 var config = new ConfigurationBuilder ( )
2341 . AddEnvironmentVariables ( )
2442#if DEBUG
@@ -45,6 +63,7 @@ public static CommandApp Create(out IServiceProvider services)
4563 } ) ;
4664
4765 collection . ConfigureSponsors ( ) ;
66+ collection . AddServices ( ) ;
4867
4968 var registrar = new TypeRegistrar ( collection ) ;
5069 var app = new CommandApp ( registrar ) ;
0 commit comments