1+ using System . CommandLine ;
2+ using Hypr . Commands ;
13using Hypr . Configuration ;
24using Hypr . Hooks ;
35using Hypr . Services ;
@@ -10,64 +12,74 @@ namespace Hypr;
1012
1113internal static class Module
1214{
13- internal static IServiceCollection AddServices ( this IServiceCollection services , IConfiguration configuration ) => services
14- . Configure < TerminalConfig > ( configuration . GetSection ( "terminal" ) )
15- . Configure < WorktreeConfig > ( configuration . GetSection ( "worktree" ) )
16- . Configure < CleanupConfig > ( configuration . GetSection ( "cleanup" ) )
17- . Configure < ScriptsConfig > ( configuration . GetSection ( "scripts" ) )
18- . Configure < ConfirmationsConfig > ( configuration . GetSection ( "confirmations" ) )
19- . AddSingleton < StateService > ( )
20- . AddSingleton < GitService > ( )
21- . AddSingleton < GitHubService > ( )
22- . AddSingleton < TerminalService > ( )
23- . AddSingleton < VersionCheckService > ( )
24- . AddSingleton < HookRunner > ( )
25- . AddTerminalProviders ( ) ;
15+ internal static IServiceCollection AddServices ( this IServiceCollection services , IConfiguration configuration ) => services
16+ // Configuration sections
17+ . Configure < TerminalConfig > ( configuration . GetSection ( "terminal" ) )
18+ . Configure < WorktreeConfig > ( configuration . GetSection ( "worktree" ) )
19+ . Configure < CleanupConfig > ( configuration . GetSection ( "cleanup" ) )
20+ . Configure < ScriptsConfig > ( configuration . GetSection ( "scripts" ) )
21+ . Configure < ConfirmationsConfig > ( configuration . GetSection ( "confirmations" ) )
22+ // Services
23+ . AddSingleton < StateService > ( )
24+ . AddSingleton < GitService > ( )
25+ . AddSingleton < GitHubService > ( )
26+ . AddSingleton < TerminalService > ( )
27+ . AddSingleton < VersionCheckService > ( )
28+ . AddSingleton < HookRunner > ( )
29+ // Commands and terminal providers (explicit registration for commands, Scrutor for terminal providers)
30+ . AddCommands ( )
31+ . AddTerminalProviders ( ) ;
2632
27- private static IServiceCollection AddTerminalProviders ( this IServiceCollection services )
28- {
29- var currentPlatform = GetCurrentPlatform ( ) ;
33+ internal static IServiceCollection AddCommands ( this IServiceCollection services ) => services
34+ . AddSingleton < Command , ListCommand > ( )
35+ . AddSingleton < Command , SwitchCommand > ( )
36+ . AddSingleton < Command , ConfigCommand > ( )
37+ . AddSingleton < Command , CleanupCommand > ( ) ;
3038
31- // Use Scrutor to scan and register all terminal providers that support the current platform
32- services . Scan ( scan => scan
33- . FromAssemblyOf < ITerminalProvider > ( )
34- . AddClasses ( classes => classes
35- . AssignableTo < ITerminalProvider > ( )
36- . Where ( type => SupportsCurrentPlatform ( type , currentPlatform ) ) )
37- . AsImplementedInterfaces ( )
38- . WithSingletonLifetime ( ) ) ;
39+ private static IServiceCollection AddTerminalProviders ( this IServiceCollection services )
40+ {
41+ var currentPlatform = GetCurrentPlatform ( ) ;
3942
40- return services ;
41- }
43+ // Use Scrutor to scan and register all terminal providers that support current platform
44+ services . Scan ( scan => scan
45+ . FromAssemblyOf < ITerminalProvider > ( )
46+ . AddClasses ( classes => classes
47+ . AssignableTo < ITerminalProvider > ( )
48+ . Where ( type => SupportsCurrentPlatform ( type , currentPlatform ) ) )
49+ . AsImplementedInterfaces ( )
50+ . WithSingletonLifetime ( ) ) ;
4251
43- private static Platform GetCurrentPlatform ( )
44- {
45- if ( PlatformUtils . IsWindows ) return Platform . Windows ;
46- if ( PlatformUtils . IsMacOS ) return Platform . MacOS ;
47- if ( PlatformUtils . IsLinux ) return Platform . Linux ;
48- return Platform . None ;
49- }
52+ return services ;
53+ }
5054
51- private static bool SupportsCurrentPlatform ( Type providerType , Platform currentPlatform )
52- {
53- return GetSupportedPlatformsForType ( providerType ) . HasFlag ( currentPlatform ) ;
54- }
55+ private static Platform GetCurrentPlatform ( )
56+ {
57+ if ( PlatformUtils . IsWindows ) return Platform . Windows ;
58+ if ( PlatformUtils . IsMacOS ) return Platform . MacOS ;
59+ if ( PlatformUtils . IsLinux ) return Platform . Linux ;
60+ return Platform . None ;
61+ }
62+
63+ private static bool SupportsCurrentPlatform ( Type providerType , Platform currentPlatform )
64+ {
65+ return GetSupportedPlatformsForType ( providerType ) . HasFlag ( currentPlatform ) ;
66+ }
5567
56- private static Platform GetSupportedPlatformsForType ( Type providerType )
68+ private static Platform GetSupportedPlatformsForType ( Type providerType )
69+ {
70+ // Map known provider types to their supported platforms
71+ return providerType . Name switch
5772 {
58- // Map known provider types to their supported platforms
59- return providerType . Name switch
60- {
61- nameof ( WindowsTerminalProvider ) => Platform . Windows ,
62- nameof ( ITerm2Provider ) => Platform . MacOS ,
63- nameof ( TerminalAppProvider ) => Platform . MacOS ,
64- nameof ( GnomeTerminalProvider ) => Platform . Linux ,
65- nameof ( TmuxProvider ) => Platform . Linux | Platform . MacOS ,
66- nameof ( VSCodeProvider ) => Platform . All ,
67- nameof ( CursorProvider ) => Platform . All ,
68- nameof ( EchoProvider ) => Platform . All ,
69- nameof ( InplaceProvider ) => Platform . All ,
70- _ => Platform . None
71- } ;
72- }
73- }
73+ nameof ( WindowsTerminalProvider ) => Platform . Windows ,
74+ nameof ( ITerm2Provider ) => Platform . MacOS ,
75+ nameof ( TerminalAppProvider ) => Platform . MacOS ,
76+ nameof ( GnomeTerminalProvider ) => Platform . Linux ,
77+ nameof ( TmuxProvider ) => Platform . Linux | Platform . MacOS ,
78+ nameof ( VSCodeProvider ) => Platform . All ,
79+ nameof ( CursorProvider ) => Platform . All ,
80+ nameof ( EchoProvider ) => Platform . All ,
81+ nameof ( InplaceProvider ) => Platform . All ,
82+ _ => Platform . None
83+ } ;
84+ }
85+ }
0 commit comments