mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: Add a disabled configuration option for modules (#86)
• Add support for the disabled configuration option
This will allow you to selectively disable modules that you don't want or need. 😄
• Overwrite starship configuration file path with STARSHIP_CONFIG environment variable
• Write tests for the two configuration options that are available
This commit is contained in:
@@ -1,15 +1,36 @@
|
||||
use lazy_static::lazy_static;
|
||||
use std::io::prelude::*;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{io, process};
|
||||
|
||||
pub fn render_prompt() -> process::Command {
|
||||
lazy_static! {
|
||||
static ref MANIFEST_DIR: &'static Path = Path::new(env!("CARGO_MANIFEST_DIR"));
|
||||
pub static ref FIXTURES_DIR: PathBuf = MANIFEST_DIR.join("tests/fixtures");
|
||||
static ref EMPTY_CONFIG: PathBuf = MANIFEST_DIR.join("empty_config.toml");
|
||||
}
|
||||
|
||||
/// Run an instance of starship
|
||||
fn run_starship() -> process::Command {
|
||||
let mut command = process::Command::new("./target/debug/starship");
|
||||
command.arg("prompt");
|
||||
|
||||
command
|
||||
.arg("prompt")
|
||||
.env_clear()
|
||||
.env("PATH", env!("PATH")) // Provide the $PATH variable so that external programs are runnable
|
||||
.env("STARSHIP_CONFIG", EMPTY_CONFIG.as_os_str());
|
||||
|
||||
command
|
||||
}
|
||||
|
||||
pub fn render_module(module_name: &str) -> process::Command {
|
||||
let mut command = process::Command::new("./target/debug/starship");
|
||||
command.arg("module").arg(module_name);
|
||||
|
||||
command
|
||||
.arg("module")
|
||||
.arg(module_name)
|
||||
.env_clear()
|
||||
.env("PATH", env!("PATH")) // Provide the $PATH variable so that external programs are runnable
|
||||
.env("STARSHIP_CONFIG", EMPTY_CONFIG.as_os_str());
|
||||
|
||||
command
|
||||
}
|
||||
@@ -20,3 +41,21 @@ pub fn new_tempdir() -> io::Result<tempfile::TempDir> {
|
||||
// "/var/folders", which provides us with restricted permissions (rwxr-xr-x)
|
||||
tempfile::tempdir_in("/tmp")
|
||||
}
|
||||
|
||||
/// Extends `std::process::Command` with methods for testing
|
||||
pub trait TestCommand {
|
||||
fn use_config(&mut self, toml: toml::value::Value) -> &mut process::Command;
|
||||
}
|
||||
|
||||
impl TestCommand for process::Command {
|
||||
/// Create a configuration file with the provided TOML and use it
|
||||
fn use_config(&mut self, toml: toml::value::Value) -> &mut process::Command {
|
||||
// Create a persistent config file in a tempdir
|
||||
let (mut config_file, config_path) =
|
||||
tempfile::NamedTempFile::new().unwrap().keep().unwrap();
|
||||
write!(config_file, "{}", toml.to_string()).unwrap();
|
||||
|
||||
// Set that newly-created file as the config for the prompt instance
|
||||
self.env("STARSHIP_CONFIG", config_path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user