1
0
Fork 0
mirror of https://codeberg.org/icewind/haze.git synced 2026-06-03 17:14:08 +02:00

fix db logs

This commit is contained in:
Robin Appelman 2021-08-26 18:40:06 +02:00
commit 17b5496879

View file

@ -1,5 +1,5 @@
use crate::cloud::CloudOptions; use crate::cloud::CloudOptions;
use crate::service::Service; use crate::service::{Service, ServiceTrait};
use color_eyre::{Report, Result}; use color_eyre::{Report, Result};
use parse_display::Display; use parse_display::Display;
use std::fmt::Display; use std::fmt::Display;
@ -36,7 +36,7 @@ pub enum HazeArgs {
Clean, Clean,
Logs { Logs {
filter: Option<String>, filter: Option<String>,
service: Option<Service>, service: Option<LogService>,
count: Option<usize>, count: Option<usize>,
}, },
Open { Open {
@ -51,6 +51,32 @@ pub enum HazeArgs {
}, },
} }
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum LogService {
Service(Service),
Database,
}
impl LogService {
pub fn from_type(ty: &str) -> Option<Self> {
if ty == "db" {
return Some(LogService::Database);
}
Some(LogService::Service(
Service::from_type(ty)?.first()?.clone(),
))
}
pub fn container_name(&self, cloud_id: &str) -> String {
match self {
LogService::Database => {
format!("{}-db", cloud_id)
}
LogService::Service(service) => service.container_name(cloud_id),
}
}
}
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub enum ExecService { pub enum ExecService {
Db, Db,
@ -145,8 +171,7 @@ impl HazeArgs {
let service = args let service = args
.peek() .peek()
.map(|s| s.as_ref()) .map(|s| s.as_ref())
.and_then(Service::from_type) .and_then(LogService::from_type);
.and_then(|list| list.first().cloned());
if service.is_some() { if service.is_some() {
let _ = args.next(); let _ = args.next();
} }