Skip to content

Commit de1f32b

Browse files
authored
Refactoring: improve structure (#74)
1 parent abcc867 commit de1f32b

35 files changed

+757
-703
lines changed

Cargo.lock

+22-13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rooz"
3-
version = "0.95.0"
3+
version = "0.96.0"
44
edition = "2021"
55

66
[dependencies]

src/api/container.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ use tokio::time::sleep;
2222

2323
use crate::{
2424
api::ContainerApi,
25-
backend::ContainerBackend,
26-
labels::{KeyValue, Labels},
2725
model::types::{AnyError, ContainerResult, RunSpec},
26+
util::backend::ContainerBackend,
27+
util::labels::{KeyValue, Labels},
2828
};
2929

3030
pub fn inject(script: &str, name: &str) -> Vec<String> {
@@ -52,6 +52,14 @@ impl<'a> ContainerApi<'a> {
5252
Ok(self.client.list_containers(Some(list_options)).await?)
5353
}
5454

55+
pub async fn get_single(&self, labels: &Labels) -> Result<Option<ContainerSummary>, AnyError> {
56+
match self.get_all(&labels).await?.as_slice() {
57+
[] => Ok(None),
58+
[container] => Ok(Some(container.clone())),
59+
_ => panic!("Too many containers found"),
60+
}
61+
}
62+
5563
pub async fn remove(&self, container_id: &str, force: bool) -> Result<(), AnyError> {
5664
let force_display = if force { " (force)" } else { "" };
5765

src/api/exec.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
api::container, api::ExecApi, backend::ContainerBackend, constants, model::types::AnyError,
2+
api::container, api::ExecApi, constants, model::types::AnyError,
3+
util::backend::ContainerBackend,
34
};
45
use bollard::{
56
container::LogOutput,

src/api/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use bollard::Docker;
22

3-
use crate::backend::ContainerBackend;
3+
use crate::util::backend::ContainerBackend;
44

55
pub mod container;
66
pub mod exec;

src/api/sidecar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use bollard::network::CreateNetworkOptions;
44

55
use crate::{
66
api::WorkspaceApi,
7+
config::config::{RoozCfg, RoozSidecar},
78
constants,
8-
labels::{self, Labels},
99
model::{
10-
config::{RoozCfg, RoozSidecar},
1110
types::{AnyError, RunSpec},
1211
volume::RoozVolume,
1312
},
13+
util::labels::{self, Labels},
1414
};
1515

1616
impl<'a> WorkspaceApi<'a> {

src/api/volume.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::{
22
api::VolumeApi,
3-
labels::Labels,
43
model::{
54
types::{AnyError, VolumeResult},
65
volume::{RoozVolume, RoozVolumeRole},
76
},
7+
util::labels::Labels,
88
};
99
use bollard::{errors::Error::DockerResponseServerError, volume::RemoveVolumeOptions};
1010
use bollard::{service::Mount, volume::CreateVolumeOptions};

0 commit comments

Comments
 (0)