From 60ce3209124a5942e19f2793ae444671361db870 Mon Sep 17 00:00:00 2001 From: Thomas O'Donnell Date: Sun, 12 Jan 2020 23:50:25 +0100 Subject: [PATCH] refactor(php): Use `exec_cmd` util(#825) --- src/modules/php.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/modules/php.rs b/src/modules/php.rs index 3e29ca1f..4311d35f 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> { 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> { } } -fn get_php_version() -> Option { - 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 { let mut formatted_version = String::with_capacity(php_version.len() + 1); formatted_version.push('v');