@@ -227,6 +227,10 @@ module NBomberRunner =
227227 let registerScenarios ( scenarios : Contracts.Scenario list ) =
228228 { NBomberContext.empty with RegisteredScenarios = scenarios }
229229
230+ /// Sets target scenarios among all registered that will execute
231+ let withTargetScenarios ( scenarioNames : string list ) ( context : NBomberContext ) =
232+ context |> NBomberContext.setTargetScenarios scenarioNames
233+
230234 /// Sets test suite name
231235 /// Default value is: nbomber_default_test_suite_name.
232236 let withTestSuite ( testSuite : string ) ( context : NBomberContext ) =
@@ -320,27 +324,33 @@ module NBomberRunner =
320324 { context with UseHintsAnalyzer = false }
321325
322326 let internal executeCliArgs ( args ) ( context : NBomberContext ) =
323- let invokeConfigLoader ( configName ) ( configLoader ) ( config ) ( context ) =
324- if config = String.Empty then $" {configName} is empty" |> failwith
325- elif String.IsNullOrEmpty config then context
326- else configLoader config context
327+ let loadConfigFn ( loadConfig ) ( configName ) ( configPath ) ( context ) =
328+ if configPath = String.Empty then failwith $" {configName} is empty"
329+ elif isNull configPath then context
330+ else loadConfig configPath context
331+
332+ let setTargetScenarios ( targetScenarios : string seq ) ( context : NBomberContext ) =
333+ if Seq.isEmpty targetScenarios then context
334+ else NBomberContext.setTargetScenarios ( List.ofSeq targetScenarios) context
327335
328336 match CommandLine.Parser.Default.ParseArguments< CommandLineArgs>( args) with
329337 | :? Parsed< CommandLineArgs> as parsed ->
330- let values = parsed.Value
331- let execLoadConfigCmd = invokeConfigLoader " config" loadConfig values .Config
332- let execLoadInfraConfigCmd = invokeConfigLoader " infra config" loadInfraConfig values .InfraConfig
333- let execCmd = execLoadConfigCmd >> execLoadInfraConfigCmd
338+ let cliArgs = parsed.Value
339+ let loadCnf = loadConfigFn loadConfig " config" cliArgs .Config
340+ let loadInfra = loadConfigFn loadInfraConfig " infra config" cliArgs .InfraConfig
341+ let run = loadCnf >> loadInfra >> setTargetScenarios ( cliArgs.TargetScenarios )
334342
335- context |> execCmd
343+ run context
336344
337345 | _ -> context
338346
339347 let internal runWithResult ( args ) ( context : NBomberContext ) =
340348 GCSettings.LatencyMode <- GCLatencyMode.SustainedLowLatency
341- context
342- |> executeCliArgs args
343- |> NBomberRunner.run
349+
350+ if Seq.isEmpty args then
351+ NBomberRunner.run context
352+ else
353+ context |> executeCliArgs args |> NBomberRunner.run
344354
345355 let run ( context : NBomberContext ) =
346356 context
0 commit comments