Skip to content

Commit ad2abf8

Browse files
authored
Merge pull request #85 from slaveOftime/feature/disablePrintCommand
Add optional argument disablePrintCommand
2 parents 2f0a728 + cb148a0 commit ad2abf8

2 files changed

Lines changed: 50 additions & 30 deletions

File tree

Fun.Build/BuiltinCmds.fs

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,48 @@ module BuiltinCmds =
6363
type StageContext with
6464

6565
/// Run a command string with current context
66-
member ctx.RunCommand(commandStr: string, ?step: int, ?workingDir: string, ?disablePrintOutput: bool, ?cancellationToken: CancellationToken) = async {
67-
let disablePrintOutput = defaultArg disablePrintOutput false
68-
let command = ctx.BuildCommand(commandStr, ?workingDir = workingDir)
69-
let noPrefixForStep = ctx.GetNoPrefixForStep()
70-
let prefix =
71-
if noPrefixForStep then
72-
""
73-
else
74-
match step with
75-
| Some i -> ctx.BuildStepPrefix i
76-
| None -> ctx.GetNamePath()
66+
member ctx.RunCommand
67+
(
68+
commandStr: string,
69+
?step: int,
70+
?workingDir: string,
71+
?disablePrintOutput: bool,
72+
?disablePrintCommand: bool,
73+
?cancellationToken: CancellationToken
74+
) =
75+
async {
76+
let disablePrintOutput = defaultArg disablePrintOutput false
77+
let disablePrintCommand = defaultArg disablePrintCommand false
78+
let command = ctx.BuildCommand(commandStr, ?workingDir = workingDir)
79+
let noPrefixForStep = ctx.GetNoPrefixForStep()
80+
let prefix =
81+
if noPrefixForStep then
82+
""
83+
else
84+
match step with
85+
| Some i -> ctx.BuildStepPrefix i
86+
| None -> ctx.GetNamePath()
7787

78-
if not noPrefixForStep then AnsiConsole.Markup $"[green]{prefix}[/] "
79-
AnsiConsole.WriteLine commandStr
88+
if not noPrefixForStep then AnsiConsole.Markup $"[green]{prefix}[/] "
89+
if not disablePrintCommand then AnsiConsole.WriteLine commandStr
8090

81-
let ct = defaultArg cancellationToken CancellationToken.None
91+
let ct = defaultArg cancellationToken CancellationToken.None
8292

83-
let! result =
84-
Process.StartAsync(
85-
command,
86-
commandStr,
87-
prefix,
88-
printOutput = (not disablePrintOutput && not (ctx.GetNoStdRedirectForStep())),
89-
cancellationToken = ct
90-
)
93+
let! result =
94+
Process.StartAsync(
95+
command,
96+
commandStr,
97+
prefix,
98+
printOutput = (not disablePrintOutput && not (ctx.GetNoStdRedirectForStep())),
99+
cancellationToken = ct
100+
)
91101

92-
return
93-
if ct.IsCancellationRequested then
94-
Ok()
95-
else
96-
ctx.MapExitCodeToResult result.ExitCode
97-
}
102+
return
103+
if ct.IsCancellationRequested then
104+
Ok()
105+
else
106+
ctx.MapExitCodeToResult result.ExitCode
107+
}
98108

99109
/// <summary>
100110
/// Run a command string with current context, and return the standard output if the exit code is acceptable.
@@ -108,10 +118,12 @@ module BuiltinCmds =
108118
?step: int,
109119
?workingDir: string,
110120
?disablePrintOutput: bool,
121+
?disablePrintCommand: bool,
111122
?cancellationToken: CancellationToken
112123
) =
113124
async {
114125
let disablePrintOutput = defaultArg disablePrintOutput false
126+
let disablePrintCommand = defaultArg disablePrintCommand false
115127
let command = ctx.BuildCommand(commandStr, ?workingDir = workingDir)
116128
let noPrefixForStep = ctx.GetNoPrefixForStep()
117129
let prefix =
@@ -123,7 +135,7 @@ module BuiltinCmds =
123135
| None -> ctx.GetNamePath()
124136

125137
if not noPrefixForStep then AnsiConsole.Markup $"[green]{prefix}[/] "
126-
AnsiConsole.WriteLine commandStr
138+
if not disablePrintCommand then AnsiConsole.WriteLine commandStr
127139

128140
let ct = defaultArg cancellationToken CancellationToken.None
129141

@@ -153,10 +165,12 @@ module BuiltinCmds =
153165
?step: int,
154166
?workingDir: string,
155167
?disablePrintOutput: bool,
168+
?disablePrintCommand: bool,
156169
?cancellationToken: CancellationToken
157170
) : Async<Result<string, string>> =
158171
async {
159172
let disablePrintOutput = defaultArg disablePrintOutput false
173+
let disablePrintCommand = defaultArg disablePrintCommand false
160174
let command = ctx.BuildCommand(commandStr.ToString(), ?workingDir = workingDir)
161175
let noPrefixForStep = ctx.GetNoPrefixForStep()
162176
let args: obj[] = Array.create commandStr.ArgumentCount "*"
@@ -171,7 +185,7 @@ module BuiltinCmds =
171185
| None -> ctx.GetNamePath()
172186

173187
if not noPrefixForStep then AnsiConsole.Markup $"[green]{prefix}[/] "
174-
AnsiConsole.WriteLine encryptiedStr
188+
if not disablePrintCommand then AnsiConsole.WriteLine encryptiedStr
175189

176190
let ct = defaultArg cancellationToken CancellationToken.None
177191

@@ -200,13 +214,15 @@ module BuiltinCmds =
200214
?step: int,
201215
?workingDir: string,
202216
?disablePrintOutput: bool,
217+
?disablePrintCommand: bool,
203218
?cancellationToken: CancellationToken
204219
) : Async<Result<unit, string>> =
205220
ctx.RunSensitiveCommandCaptureOutput(
206221
commandStr,
207222
?step = step,
208223
?workingDir = workingDir,
209224
?disablePrintOutput = disablePrintOutput,
225+
?disablePrintCommand = disablePrintCommand,
210226
?cancellationToken = cancellationToken
211227
)
212228
|> AsyncResult.map ignore

Fun.Build/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## [Unreleased]
44

5+
## [1.1.16] - 2025-01-13
6+
7+
- Add optional argument disablePrintCommand
8+
59
## [1.1.15] - 2024-11-27
610

711
- Divide cmd args into CmdArgs and RemainingCmdArgs by **--**, [request](https://github.com/slaveOftime/Fun.Build/issues/81)

0 commit comments

Comments
 (0)