66using Proxxi . Core . ProxyWriters ;
77using Proxxi . Plugin . Loader . Extensions ;
88using Proxxi . Plugin . Loader . PluginLoaders ;
9+ using Proxxi . Plugin . Sdk . Models ;
910using Proxxi . Plugin . Sdk . ProxySources ;
1011
1112using Spectre . Console ;
@@ -29,6 +30,8 @@ public override async Task<int> ExecuteAsync(CommandContext context, FetchComman
2930 Stream stream ;
3031 OutputFormat format ;
3132
33+ var protocols = settings . Protocols ?? Protocols . None ;
34+
3235 if ( settings . Output != null )
3336 {
3437 stream = File . OpenWrite ( settings . Output ) ;
@@ -54,14 +57,14 @@ public override async Task<int> ExecuteAsync(CommandContext context, FetchComman
5457 if ( writer is not IStreamProxyWriter streamProxyWriter )
5558 throw new InvalidOperationException ( $ "{ format } output does not support stream mode.") ;
5659
57- await FetchAndWriteProxiesAsync ( streamProxySource , streamProxyWriter , ct ) ;
60+ await FetchAndWriteProxiesAsync ( streamProxySource , streamProxyWriter , protocols , ct ) ;
5861 }
5962 else
6063 {
6164 if ( writer is not IBatchProxyWriter batchProxyWriter )
6265 throw new InvalidOperationException ( $ "{ format } output does not support stream mode.") ;
6366
64- await FetchAndWriteProxiesAsync ( batchProxySource , batchProxyWriter , ct ) ;
67+ await FetchAndWriteProxiesAsync ( batchProxySource , batchProxyWriter , protocols , ct ) ;
6568 }
6669
6770 return 0 ;
@@ -105,24 +108,30 @@ public override async Task<int> ExecuteAsync(CommandContext context, FetchComman
105108 }
106109
107110 private static async Task FetchAndWriteProxiesAsync ( IBatchProxySource ? batchProxySource ,
108- IBatchProxyWriter writer , CancellationToken ct )
111+ IBatchProxyWriter writer , Protocols protocols , CancellationToken ct )
109112 {
110113 if ( batchProxySource == null )
111114 throw new InvalidOperationException ( "The plugin does not support batch mode." ) ;
112115
113116 var proxies = await batchProxySource . FetchAsync ( ct ) ;
114117
118+ if ( protocols != Protocols . None )
119+ proxies = proxies . Where ( p => ( p . Protocols & protocols ) != Protocols . None ) ;
120+
115121 await writer . WriteAsync ( proxies , ct ) ;
116122 }
117123
118124 private static async Task FetchAndWriteProxiesAsync ( IStreamProxySource ? streamProxySource ,
119- IStreamProxyWriter writer , CancellationToken ct )
125+ IStreamProxyWriter writer , Protocols protocols , CancellationToken ct )
120126 {
121127 if ( streamProxySource == null )
122128 throw new InvalidOperationException ( "The plugin does not support stream mode." ) ;
123129
124130 var proxies = streamProxySource . FetchAsync ( ct ) ;
125131
132+ if ( protocols != Protocols . None )
133+ proxies = proxies . Where ( p => ( p . Protocols & protocols ) != Protocols . None ) ;
134+
126135 await writer . WriteAsync ( proxies , ct ) ;
127136 }
128137
0 commit comments