mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat(php): Configure when the module is shown (#2356)
This makes it possible to configure when the php module is shown based on the contents of a directory. This should make it possible to be a lot more granular when configuring the module.
This commit is contained in:
@@ -8,6 +8,9 @@ pub struct PhpConfig<'a> {
|
||||
pub style: &'a str,
|
||||
pub format: &'a str,
|
||||
pub disabled: bool,
|
||||
pub detect_extensions: Vec<&'a str>,
|
||||
pub detect_files: Vec<&'a str>,
|
||||
pub detect_folders: Vec<&'a str>,
|
||||
}
|
||||
|
||||
impl<'a> RootModuleConfig<'a> for PhpConfig<'a> {
|
||||
@@ -17,6 +20,9 @@ impl<'a> RootModuleConfig<'a> for PhpConfig<'a> {
|
||||
style: "147 bold",
|
||||
format: "via [$symbol($version )]($style)",
|
||||
disabled: false,
|
||||
detect_extensions: vec!["php"],
|
||||
detect_files: vec!["composer.json", ".php-version"],
|
||||
detect_folders: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-9
@@ -4,24 +4,20 @@ use crate::configs::php::PhpConfig;
|
||||
use crate::formatter::StringFormatter;
|
||||
|
||||
/// Creates a module with the current PHP version
|
||||
///
|
||||
/// Will display the PHP version if any of the following criteria are met:
|
||||
/// - Current directory contains a `.php` file
|
||||
/// - Current directory contains a `composer.json` or `.php-version` file
|
||||
pub fn module<'a>(context: &'a Context) -> Option<Module<'a>> {
|
||||
let mut module = context.new_module("php");
|
||||
let config: PhpConfig = PhpConfig::try_load(module.config);
|
||||
let is_php_project = context
|
||||
.try_begin_scan()?
|
||||
.set_files(&["composer.json", ".php-version"])
|
||||
.set_extensions(&["php"])
|
||||
.set_files(&config.detect_files)
|
||||
.set_folders(&config.detect_folders)
|
||||
.set_extensions(&config.detect_extensions)
|
||||
.is_match();
|
||||
|
||||
if !is_php_project {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut module = context.new_module("php");
|
||||
let config: PhpConfig = PhpConfig::try_load(module.config);
|
||||
|
||||
let parsed = StringFormatter::new(config.format).and_then(|formatter| {
|
||||
formatter
|
||||
.map_meta(|variable, _| match variable {
|
||||
|
||||
Reference in New Issue
Block a user