Skip to content

Commit 1adc0fd

Browse files
committed
cmd: add Command::log_command to disable logging cmd name and args
1 parent 7c07687 commit 1adc0fd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- New method `Crate::purge_from_cache` to remove the cached copy of a crate.
1515
- New method `BuildBuilder::patch_with_git` to replace crates.
1616
- New method `BuildBuilder::run` to run a build.
17+
- New method `Command::log_command` to disable logging the command name and
18+
args before executing it.
1719

1820
### Changed
1921

src/cmd/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub struct Command<'w, 'pl> {
129129
cd: Option<PathBuf>,
130130
timeout: Option<Duration>,
131131
no_output_timeout: Option<Duration>,
132+
log_command: bool,
132133
log_output: bool,
133134
}
134135

@@ -179,6 +180,7 @@ impl<'w, 'pl> Command<'w, 'pl> {
179180
timeout,
180181
no_output_timeout,
181182
log_output: true,
183+
log_command: true,
182184
}
183185
}
184186

@@ -261,6 +263,15 @@ impl<'w, 'pl> Command<'w, 'pl> {
261263
self
262264
}
263265

266+
/// Enable or disable logging the command name and args to the [`log` crate][log] before the
267+
/// exectuion. By default logging is enabled.
268+
///
269+
/// [log]: (https://crates.io/crates/log)
270+
pub fn log_command(mut self, log_command: bool) -> Self {
271+
self.log_command = log_command;
272+
self
273+
}
274+
264275
/// Run the prepared command and return an error if it fails (for example with a non-zero exit
265276
/// code or a timeout).
266277
pub fn run(self) -> Result<(), Error> {
@@ -389,7 +400,9 @@ impl<'w, 'pl> Command<'w, 'pl> {
389400
cmd.current_dir(cd);
390401
}
391402

392-
info!("running `{}`", cmdstr);
403+
if self.log_command {
404+
info!("running `{}`", cmdstr);
405+
}
393406
let out = log_command(
394407
cmd,
395408
self.process_lines,

0 commit comments

Comments
 (0)