@@ -39,6 +39,8 @@ internal class ProxyHost
3939 private readonly Option < long ? > _timeoutOption ;
4040 internal static readonly string DiscoverOptionName = "--discover" ;
4141 private readonly Option < bool ? > _discoverOption ;
42+ internal static readonly string EnvOptionName = "--env" ;
43+ private readonly Option < string [ ] ? > _envOption ;
4244
4345 private static bool _configFileResolved = false ;
4446 private static string _configFile = "devproxyrc.json" ;
@@ -273,7 +275,7 @@ public ProxyHost()
273275 Arity = ArgumentArity . ZeroOrMore
274276 } ;
275277 _urlsToWatchOption . AddAlias ( "-u" ) ;
276-
278+
277279 _timeoutOption = new Option < long ? > ( TimeoutOptionName , "Time in seconds after which Dev Proxy exits. Resets when Dev Proxy intercepts a request." )
278280 {
279281 ArgumentHelpName = "timeout" ,
@@ -294,6 +296,40 @@ public ProxyHost()
294296 } ) ;
295297 _timeoutOption . AddAlias ( "-t" ) ;
296298
299+ _envOption = new Option < string [ ] ? > ( EnvOptionName , "Variables to set for the Dev Proxy process" )
300+ {
301+ ArgumentHelpName = "env" ,
302+ AllowMultipleArgumentsPerToken = true ,
303+ Arity = ArgumentArity . ZeroOrMore
304+ } ;
305+ _envOption . AddAlias ( "-e" ) ;
306+ _envOption . AddValidator ( input =>
307+ {
308+ try
309+ {
310+ var envVars = input . GetValueForOption ( _envOption ) ;
311+ if ( envVars is null || envVars . Length == 0 )
312+ {
313+ return ;
314+ }
315+
316+ foreach ( var envVar in envVars )
317+ {
318+ // Split on first '=' only
319+ var parts = envVar . Split ( '=' , 2 ) ;
320+ if ( parts . Length != 2 )
321+ {
322+ input . ErrorMessage = $ "Invalid environment variable format: '{ envVar } '. Expected format is 'name=value'.";
323+ return ;
324+ }
325+ }
326+ }
327+ catch ( InvalidOperationException ex )
328+ {
329+ input . ErrorMessage = ex . Message ;
330+ }
331+ } ) ;
332+
297333 ProxyCommandHandler . Configuration . ConfigFile = ConfigFile ;
298334 }
299335
@@ -318,7 +354,8 @@ public RootCommand GetRootCommand(ILogger logger)
318354 // As such, it's always set here
319355 _urlsToWatchOption ! ,
320356 _timeoutOption ,
321- _discoverOption
357+ _discoverOption ,
358+ _envOption
322359 } ;
323360 command . Description = "Dev Proxy is a command line tool for testing Microsoft Graph, SharePoint Online and any other HTTP APIs." ;
324361
@@ -492,6 +529,7 @@ public RootCommand GetRootCommand(ILogger logger)
492529 _installCertOption ,
493530 _timeoutOption ,
494531 _discoverOption ,
532+ _envOption ,
495533 .. optionsFromPlugins ,
496534 ] ,
497535 urlsToWatch ,
0 commit comments