mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +02:00
move cloud list into struct
This commit is contained in:
parent
a30d1c9d64
commit
6041587c05
2 changed files with 89 additions and 89 deletions
52
src/cloud.rs
52
src/cloud.rs
|
|
@ -290,32 +290,12 @@ impl Cloud {
|
|||
pub async fn exec(&self, docker: &mut Docker, cmd: Vec<String>) -> Result<()> {
|
||||
exec_tty(docker, &self.id, "haze", cmd, vec![]).await
|
||||
}
|
||||
}
|
||||
|
||||
async fn setup_workdir(base: &Utf8Path, id: &str) -> Result<Utf8PathBuf> {
|
||||
let workdir = base.join(id);
|
||||
create_dir_all(workdir.join("data")).await?;
|
||||
create_dir_all(workdir.join("config")).await?;
|
||||
create_dir_all(workdir.join("data-autotest")).await?;
|
||||
create_dir_all(workdir.join("skeleton")).await?;
|
||||
create_dir_all(workdir.join("integration/output")).await?;
|
||||
create_dir_all(workdir.join("integration/work")).await?;
|
||||
create_dir_all(workdir.join("integration/vendor")).await?;
|
||||
|
||||
write(workdir.join("integration/composer.lock"), "").await?;
|
||||
write(workdir.join("config/CAN_INSTALL"), "").await?;
|
||||
write(workdir.join("phpunit-cache"), "").await?;
|
||||
|
||||
create_dir_all(base.join("composer/cache")).await?;
|
||||
|
||||
Ok(workdir)
|
||||
}
|
||||
|
||||
pub async fn list(
|
||||
pub async fn list(
|
||||
docker: &mut Docker,
|
||||
filter: Option<String>,
|
||||
config: &HazeConfig,
|
||||
) -> Result<Vec<Cloud>> {
|
||||
) -> Result<Vec<Cloud>> {
|
||||
let containers = docker
|
||||
.list_containers::<String>(Some(ListContainersOptions {
|
||||
all: true,
|
||||
|
|
@ -377,16 +357,36 @@ pub async fn list(
|
|||
.into_iter()
|
||||
.map(|(_created, cloud)| cloud)
|
||||
.collect())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_by_filter(
|
||||
pub async fn get_by_filter(
|
||||
docker: &mut Docker,
|
||||
filter: Option<String>,
|
||||
config: &HazeConfig,
|
||||
) -> Result<Cloud> {
|
||||
list(docker, filter, config)
|
||||
) -> Result<Cloud> {
|
||||
Cloud::list(docker, filter, config)
|
||||
.await?
|
||||
.into_iter()
|
||||
.next()
|
||||
.ok_or(Report::msg("No clouds running matching filter"))
|
||||
}
|
||||
}
|
||||
|
||||
async fn setup_workdir(base: &Utf8Path, id: &str) -> Result<Utf8PathBuf> {
|
||||
let workdir = base.join(id);
|
||||
create_dir_all(workdir.join("data")).await?;
|
||||
create_dir_all(workdir.join("config")).await?;
|
||||
create_dir_all(workdir.join("data-autotest")).await?;
|
||||
create_dir_all(workdir.join("skeleton")).await?;
|
||||
create_dir_all(workdir.join("integration/output")).await?;
|
||||
create_dir_all(workdir.join("integration/work")).await?;
|
||||
create_dir_all(workdir.join("integration/vendor")).await?;
|
||||
|
||||
write(workdir.join("integration/composer.lock"), "").await?;
|
||||
write(workdir.join("config/CAN_INSTALL"), "").await?;
|
||||
write(workdir.join("phpunit-cache"), "").await?;
|
||||
|
||||
create_dir_all(base.join("composer/cache")).await?;
|
||||
|
||||
Ok(workdir)
|
||||
}
|
||||
|
|
|
|||
18
src/main.rs
18
src/main.rs
|
|
@ -1,5 +1,5 @@
|
|||
use crate::args::{HazeArgs, HazeCommand};
|
||||
use crate::cloud::{get_by_filter, list, Cloud, CloudOptions};
|
||||
use crate::cloud::{Cloud, CloudOptions};
|
||||
use crate::config::HazeConfig;
|
||||
use bollard::Docker;
|
||||
use color_eyre::{eyre::WrapErr, Report, Result};
|
||||
|
|
@ -22,7 +22,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
match args.command {
|
||||
HazeCommand::Clean => {
|
||||
let list = list(&mut docker, None, &config).await?;
|
||||
let list = Cloud::list(&mut docker, None, &config).await?;
|
||||
for cloud in list {
|
||||
if let Err(e) = cloud.destroy(&mut docker).await {
|
||||
eprintln!("Error while removing cloud: {:#}", e);
|
||||
|
|
@ -30,7 +30,7 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
}
|
||||
HazeCommand::List => {
|
||||
let list = list(&mut docker, args.options.first().cloned(), &config).await?;
|
||||
let list = Cloud::list(&mut docker, args.options.first().cloned(), &config).await?;
|
||||
for cloud in list {
|
||||
if let Some(filter) = &args.id {
|
||||
if !cloud.id.contains(filter.as_str()) {
|
||||
|
|
@ -63,18 +63,18 @@ async fn main() -> Result<()> {
|
|||
println!("http://{}", cloud.ip.unwrap());
|
||||
}
|
||||
HazeCommand::Stop => {
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||
cloud.destroy(&mut docker).await?;
|
||||
}
|
||||
HazeCommand::Logs => {
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
let cloud = 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, args.id, &config).await?;
|
||||
let cloud = Cloud::get_by_filter(&mut docker, args.id, &config).await?;
|
||||
cloud
|
||||
.exec(
|
||||
&mut docker,
|
||||
|
|
@ -87,17 +87,17 @@ async fn main() -> Result<()> {
|
|||
.await?;
|
||||
}
|
||||
HazeCommand::Occ => {
|
||||
let cloud = get_by_filter(&mut docker, args.id, &config).await?;
|
||||
let cloud = 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, args.id, &config).await?;
|
||||
let cloud = 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, args.id, &config).await?;
|
||||
let cloud = 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