From e3d4359dcba760437367e4ef72304f1bf7f967d1 Mon Sep 17 00:00:00 2001 From: slaveoftime Date: Mon, 31 Aug 2026 09:50:15 +0800 Subject: [PATCH] Fix: help without -p runs the default pipeline instead of printing help #91 --- Fun.Build.Tests/PipelineBuilderTests.fs | 43 +++++++++++++++++++++++++ Fun.Build/CHANGELOG.md | 5 +++ Fun.Build/PipelineBuilder.fs | 2 +- demo-cmd.fsx | 9 +++--- 4 files changed, 54 insertions(+), 5 deletions(-) diff --git a/Fun.Build.Tests/PipelineBuilderTests.fs b/Fun.Build.Tests/PipelineBuilderTests.fs index 273c5a2..914b832 100644 --- a/Fun.Build.Tests/PipelineBuilderTests.fs +++ b/Fun.Build.Tests/PipelineBuilderTests.fs @@ -572,3 +572,46 @@ let ``check GetAllCmdArgs and RemainingArgs works when remaining args is not pro Assert.Equal([ "-p"; "demo"; "test1"; "v1" ], actualAllCmdArgs) Assert.Equal([], actualRemainingArgs) + +[] +let ``help without -p should not run default pipeline`` () = + let mutable called = false + + pipeline "Build" { + cmdArgs [ "--help" ] + stage "build" { run (fun _ -> called <- true) } + runIfOnlySpecified false + } + + Assert.False(called) + +[] +let ``help with -p should not run pipeline`` () = + let mutable called = false + + pipeline "Build" { + cmdArgs [ "-p"; "Build"; "--help" ] + stage "build" { run (fun _ -> called <- true) } + runIfOnlySpecified + } + + Assert.False(called) + +[] +let ``help without -p should not run any pipeline when multiple exist`` () = + let mutable buildCalled = false + let mutable otherCalled = false + + pipeline "Build" { + cmdArgs [ "--help" ] + stage "build" { run (fun _ -> buildCalled <- true) } + runIfOnlySpecified false + } + pipeline "Other" { + cmdArgs [ "--help" ] + stage "other" { run (fun _ -> otherCalled <- true) } + runIfOnlySpecified true + } + + Assert.False(buildCalled) + Assert.False(otherCalled) diff --git a/Fun.Build/CHANGELOG.md b/Fun.Build/CHANGELOG.md index fc38d50..1d112ce 100644 --- a/Fun.Build/CHANGELOG.md +++ b/Fun.Build/CHANGELOG.md @@ -2,6 +2,11 @@ ## [Unreleased] +## [1.1.18] - 2026-08-31 + +- Fix: help without -p runs the default pipeline instead of printing help + #91 + ## [1.1.17] - 2025-09-23 Support run multiple pipelines in one execution diff --git a/Fun.Build/PipelineBuilder.fs b/Fun.Build/PipelineBuilder.fs index 23b9b5c..6627b80 100644 --- a/Fun.Build/PipelineBuilder.fs +++ b/Fun.Build/PipelineBuilder.fs @@ -267,7 +267,7 @@ type PipelineBuilder(name: string) = try match pipelineIndexes with - | [] when not specified -> ctx.Run() + | [] when not specified && not isHelp -> ctx.Run() | [] -> () | _ :: _ -> for i, index in Seq.indexed pipelineIndexes do diff --git a/demo-cmd.fsx b/demo-cmd.fsx index b5abe14..17e0fcb 100644 --- a/demo-cmd.fsx +++ b/demo-cmd.fsx @@ -12,10 +12,11 @@ module Apps = let all = [ app1; app2; app3 ] -let args = - {| app = fun apps -> CmdArg.Create(shortName = "-a", longName = "--app", values = apps, description = "specify the app you want to dev") - path = CmdArg.Create("-f", "--file", "publish directory for the app") - watch = CmdArg.Create(shortName = "-w", description = "if is in watch mode") |} +let args = {| + app = fun apps -> CmdArg.Create(shortName = "-a", longName = "--app", values = apps, description = "specify the app you want to dev") + path = CmdArg.Create("-f", "--file", "publish directory for the app") + watch = CmdArg.Create(shortName = "-w", description = "if is in watch mode") +|} pipeline "demo" {