1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-10-01 16:54:08 +02:00

allow opening services with haze open

This commit is contained in:
Robin Appelman 2026-09-27 17:28:59 +02:00
commit 6c440952dc
3 changed files with 37 additions and 5 deletions

View file

@ -2,6 +2,7 @@
- Support having a `#!` inside a haze script to specify the interpreter to use - Support having a `#!` inside a haze script to specify the interpreter to use
- Add webui for accessing the database. - Add webui for accessing the database.
- Allow opening services with `haze open [service]`
## 2.4.1 ## 2.4.1

View file

@ -64,6 +64,7 @@ pub enum HazeArgs {
}, },
Open { Open {
filter: Option<String>, filter: Option<String>,
service: Option<Service>,
}, },
Fmt { Fmt {
path: String, path: String,
@ -317,7 +318,21 @@ impl HazeArgs {
.into_diagnostic()?, .into_diagnostic()?,
}) })
} }
HazeCommand::Open => Ok(HazeArgs::Open { filter }), HazeCommand::Open => {
let mut args = args.peekable();
let service = match args.peek() {
Some(arg) => Service::from_type(&[], arg.as_ref())
.into_iter()
.filter_map(|services| services.into_iter().next())
.next()
.map(|service| {
args.next();
service
}),
_ => None,
};
Ok(HazeArgs::Open { filter, service })
}
HazeCommand::Fmt => { HazeCommand::Fmt => {
let path = args let path = args
.next() .next()
@ -472,6 +487,7 @@ pub enum HazeCommand {
))] ))]
Logs, Logs,
/// Open an instance in the browser /// Open an instance in the browser
#[strum(props(Args = "[service] service to open, instead of the Nextcloud instance"))]
Open, Open,
/// Run code formatting from a new instance /// Run code formatting from a new instance
#[strum(props(Args = "[path] path to format"))] #[strum(props(Args = "[path] path to format"))]

View file

@ -286,11 +286,26 @@ async fn main() -> Result<ExitCode> {
.await?; .await?;
} }
} }
HazeArgs::Open { filter } => { HazeArgs::Open { filter, service } => {
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?; let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
match cloud.ip { match service {
Some(service) => {
let Some(ip) = service.get_ips(&docker, &cloud.id).await?.next() else {
eprintln!(
"Service {} can't be opened as it has no associated IP",
service.name()
);
return Ok(ExitCode::FAILURE);
};
let addr = config
.proxy
.addr(&format!("{}-{}", &cloud.id, service.name()), ip);
opener::open(addr).into_diagnostic()?;
}
None => match cloud.ip {
Some(_) => opener::open(cloud.address).into_diagnostic()?, Some(_) => opener::open(cloud.address).into_diagnostic()?,
None => eprintln!("{} is not running", cloud.id), None => eprintln!("{} is not running", cloud.id),
},
} }
} }
HazeArgs::Test { options, mut args } => { HazeArgs::Test { options, mut args } => {