1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 09:04:12 +02:00

make it easier to change php configuration

This commit is contained in:
Robin Appelman 2026-02-06 23:55:06 +01:00
commit 4bb6a21d7c
6 changed files with 71 additions and 0 deletions

View file

@ -99,6 +99,9 @@ pub enum HazeArgs {
filter: Option<String>,
path: String,
},
Reload {
filter: Option<String>,
},
}
#[derive(
@ -379,6 +382,7 @@ impl HazeArgs {
.ok_or_else(|| Report::msg("No path provided"))?
.into(),
}),
HazeCommand::Reload => Ok(HazeArgs::Reload { filter }),
}
}
}
@ -467,6 +471,11 @@ pub enum HazeCommand {
/// Edit a file in the instance with $EDITOR on the host
#[strum(props(Args = "[path] file to edit"))]
Edit,
/// Reload the php configuration in the instance
#[strum(props(
Details = "note: you can overwrite <yellow>php.ini</yellow> settings with <literal>haze</literal> <arg>[filter]</arg> <literal>edit /php.ini</literal>"
))]
Reload,
}
impl SubCommand for HazeCommand {
@ -484,6 +493,7 @@ impl SubCommand for HazeCommand {
| HazeCommand::Unpin
| HazeCommand::Env
| HazeCommand::Edit
| HazeCommand::Reload
)
}

View file

@ -231,4 +231,32 @@ fn subcommand_help(command: &dyn SubCommand) {
);
}
}
if let Some(details) = command.get_str("Details") {
println!("{}", format_details(details));
}
}
fn format_details(details: &str) -> String {
use std::fmt::Write;
let mut result = String::with_capacity(details.len());
for (i, part) in details.split("</").enumerate() {
let part = if i > 0 {
// strip the remaining close tag from the previous part
part.split_once('>').map(|(_, part)| part).unwrap_or(part)
} else {
part
};
let (head, tail) = part.split_once('<').unwrap_or((part, ""));
result.push_str(head);
if let Some((tag, content)) = tail.split_once('>') {
match tag {
"literal" => write!(&mut result, "{}", content.blue()).unwrap(),
"arg" => write!(&mut result, "{}", content.green()).unwrap(),
"yellow" => write!(&mut result, "{}", content.bright_yellow()).unwrap(),
_ => write!(&mut result, "{content}").unwrap(),
}
}
}
result
}

View file

@ -470,6 +470,27 @@ async fn main() -> Result<ExitCode> {
.into_diagnostic()
.wrap_err("Failed to start $EDITOR");
}
HazeArgs::Reload { filter } => {
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
exec(
&docker,
&cloud.id,
"root",
vec!["pkill", "php-fpm"],
Vec::<String>::new(),
Some(stdout()),
)
.await?;
exec(
&docker,
&cloud.id,
"root",
vec!["sh", "-c", "php-fpm --fpm-config /etc/php-fpm.conf&"],
Vec::<String>::new(),
Some(stdout()),
)
.await?;
}
};
Ok(ExitCode::SUCCESS)

View file

@ -161,6 +161,7 @@ pub fn default_mappings<'a>() -> impl IntoIterator<Item = Mapping<'a>> {
.dont_create(),
Mapping::new(WorkDir, "xdebug", "/tmp/xdebug"),
Mapping::new(WorkDir, "profiling", "/tmp/profiling"),
Mapping::new(WorkDir, "php.ini", "/php.ini").file(),
];
IntoIterator::into_iter(mappings)
}