mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
config
This commit is contained in:
parent
67c2b59639
commit
56c574374e
5 changed files with 150 additions and 12 deletions
|
|
@ -1,6 +1,31 @@
|
|||
use camino::Utf8PathBuf;
|
||||
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||
use directories_next::ProjectDirs;
|
||||
use serde::Deserialize;
|
||||
use std::fs::read;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct HazeConfig {
|
||||
pub sources_root: Utf8PathBuf,
|
||||
#[serde(default = "default_work_dir")]
|
||||
pub work_dir: Utf8PathBuf,
|
||||
}
|
||||
|
||||
fn default_work_dir() -> Utf8PathBuf {
|
||||
"/tmp/haze".into()
|
||||
}
|
||||
|
||||
impl HazeConfig {
|
||||
pub fn load() -> Result<Self> {
|
||||
let dirs = ProjectDirs::from("nl", "icewind", "haze").unwrap();
|
||||
let file = dirs.config_dir().join("haze.toml");
|
||||
if !file.exists() {
|
||||
return Err(Report::msg(format!(
|
||||
"Config file not setup: {}",
|
||||
file.to_string_lossy()
|
||||
)));
|
||||
}
|
||||
let content = read(&file).wrap_err("Failed to read config file")?;
|
||||
toml::from_slice(&content).wrap_err("Failed to parse config file")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
17
src/main.rs
17
src/main.rs
|
|
@ -16,10 +16,7 @@ mod tty;
|
|||
async fn main() -> Result<()> {
|
||||
let mut docker =
|
||||
Docker::connect_with_local_defaults().wrap_err("Failed to connect to docker")?;
|
||||
let config = HazeConfig {
|
||||
sources_root: "/srv/http/owncloud".into(),
|
||||
work_dir: "/tmp/haze".into(),
|
||||
};
|
||||
let config = HazeConfig::load().wrap_err("Failed to load config")?;
|
||||
|
||||
let args = HazeArgs::parse(std::env::args())?;
|
||||
|
||||
|
|
@ -66,18 +63,18 @@ async fn main() -> Result<()> {
|
|||
println!("http://{}", cloud.ip.unwrap());
|
||||
}
|
||||
HazeCommand::Stop => {
|
||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
cloud.destroy(&mut docker).await?;
|
||||
}
|
||||
HazeCommand::Logs => {
|
||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
let logs = cloud.logs(&mut docker).await?;
|
||||
for log in logs {
|
||||
print!("{}", log);
|
||||
}
|
||||
}
|
||||
HazeCommand::Exec => {
|
||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
|
|
@ -90,17 +87,17 @@ async fn main() -> Result<()> {
|
|||
.await?;
|
||||
}
|
||||
HazeCommand::Occ => {
|
||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
let mut options = args.options;
|
||||
options.insert(0, "occ".to_string());
|
||||
cloud.exec(&mut docker, options).await?;
|
||||
}
|
||||
HazeCommand::Db => {
|
||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
cloud.db.exec(&mut docker, &cloud.id).await?;
|
||||
}
|
||||
HazeCommand::Open => {
|
||||
let cloud = get_by_filter(&mut docker, None, &config).await?;
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
match cloud.ip {
|
||||
Some(ip) => opener::open(format!("http://{}", ip))?,
|
||||
None => eprintln!("{} is not running", cloud.id),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue