feat: allow changing default command timeout (#2283)

* feat: allow changing default command timeout

* fix clippy

* add doc to exec_cmd in Context

* update docs in CONTRIBUTING.md

* Fix comment in CONTRIBUTING.md

Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>

Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
This commit is contained in:
David Knaack
2021-02-11 21:34:47 +01:00
committed by GitHub
parent 04d1332f9c
commit eccbda8328
30 changed files with 112 additions and 97 deletions
+3 -5
View File
@@ -37,7 +37,6 @@ use super::{Context, Module, RootModuleConfig};
use crate::configs::php::PhpConfig;
use crate::formatter::StringFormatter;
use crate::utils;
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
@@ -51,20 +50,19 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
## External commands
To run a external command (e.g. to get the version of a tool) and to allow for mocking use the `utils::exec_cmd` function. Here's a quick example:
To run a external command (e.g. to get the version of a tool) and to allow for mocking use the `context.exec_cmd` function. Here's a quick example:
```rust
use super::{Context, Module, RootModuleConfig};
use crate::configs::php::PhpConfig;
use crate::formatter::StringFormatter;
use crate::utils;
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
// Here `my_env_var` will be either the stdout of the called command or the function
// Here `output` will be either the stdout of the called command or the function
// will exit if the called program was not installed or could not be run.
let output = utils::exec_cmd("my_command", &["first_arg", "second_arg"])?.stdout;
let output = context.exec_cmd("my_command", &["first_arg", "second_arg"])?.stdout;
// Then you can happily use the output
}