summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas O'Donnell <andytom@users.noreply.github.com>2020-01-12 23:50:25 +0100
committerMatan Kushner <hello@matchai.me>2020-01-12 17:50:25 -0500
commit60ce3209124a5942e19f2793ae444671361db870 (patch)
tree6055ea6d25219730879c80588c58eb2b9d1cfa10 /src
parent0d81694e324a272138f2a3c5726da7ba0ab5385f (diff)
refactor(php): Use `exec_cmd` util(#825)
Diffstat (limited to 'src')
-rw-r--r--src/modules/php.rs26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/modules/php.rs b/src/modules/php.rs
index 3e29ca1fb..4311d35f1 100644
--- a/src/modules/php.rs
+++ b/src/modules/php.rs
@@ -1,8 +1,7 @@
-use std::process::Command;
-
use super::{Context, Module, RootModuleConfig, SegmentConfig};
use crate::configs::php::PhpConfig;
+use crate::utils;
/// Creates a module with the current PHP version
///
@@ -20,8 +19,16 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
return None;
}
- match get_php_version() {
- Some(php_version) => {
+ match utils::exec_cmd(
+ "php",
+ &[
+ "-r",
+ "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION;",
+ ],
+ ) {
+ Some(php_cmd_output) => {
+ let php_version = php_cmd_output.stdout;
+
let mut module = context.new_module("php");
let config: PhpConfig = PhpConfig::try_load(module.config);
@@ -37,17 +44,6 @@ pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
}
}
-fn get_php_version() -> Option<String> {
- match Command::new("php")
- .arg("-r")
- .arg("echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION;")
- .output()
- {
- Ok(output) => Some(String::from_utf8(output.stdout).unwrap()),
- Err(_) => None,
- }
-}
-
fn format_php_version(php_version: &str) -> Option<String> {
let mut formatted_version = String::with_capacity(php_version.len() + 1);
formatted_version.push('v');