1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-08-02 20:24:45 +02:00

show instance details in shell prompt

fixes #20
This commit is contained in:
Robin Appelman 2026-06-05 19:04:13 +02:00
commit 33b1fdcd6e

View file

@ -1,4 +1,3 @@
use owo_colors::OwoColorize;
use crate::config::ProxyConfig;
use crate::database::Database;
use crate::image::{image_version, pull_image, ImageVersion};
@ -12,7 +11,9 @@ use bollard::Docker;
use itertools::Itertools;
use maplit::hashmap;
use miette::{IntoDiagnostic, Report, Result, WrapErr};
use owo_colors::OwoColorize;
use reqwest::{Client, Url};
use std::iter::once;
use std::net::{IpAddr, Ipv4Addr};
use std::str::FromStr;
use std::time::Duration;
@ -129,7 +130,11 @@ impl PhpVersion {
let haze_version = ImageVersion::from_str(env!("CARGO_PKG_VERSION"));
if let (Some(image_version), Ok(haze_version)) = (image_version, haze_version) {
if image_version < haze_version {
eprintln!("{}: image version is out of date, run {} to update.", "Warning".red(), "haze update".blue());
eprintln!(
"{}: image version is out of date, run {} to update.",
"Warning".red(),
"haze update".blue()
);
eprintln!(" Haze version: {}", haze_version.bright_yellow());
eprintln!(" Image version: {}", image_version.bright_yellow());
}
@ -160,6 +165,20 @@ impl PhpVersion {
proxy_config.addr(id, IpAddr::V4(Ipv4Addr::LOCALHOST))
));
env.push(format!("INSTANCE_ID={}", id.trim_start_matches("haze-")));
env.push(format!("INSTANCE_PHP={}", self.name()));
env.push(format!("INSTANCE_DB={}", db.family()));
env.push(format!(
"INSTANCE_SERVICES={}",
once("")
.chain(services.iter().map(ServiceTrait::name))
.collect::<Vec<_>>()
.join(" ")
));
env.push(
"PS1=${INSTANCE_ID} [${INSTANCE_PHP} ${INSTANCE_DB}${INSTANCE_SERVICES}]> ".into(),
);
env.push(format!("HOST_IP={host}"));
if !proxy_config.address.is_empty() {
env.push(format!("PROXY_BASE={}", proxy_config.address));