Skip to content

Commit efaed5f

Browse files
committed
fix: valid in-repo yaml config wasn't applied
1 parent 114d6d2 commit efaed5f

File tree

5 files changed

+49
-32
lines changed

5 files changed

+49
-32
lines changed

Cargo.lock

+1-1
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.65.0"
3+
version = "0.66.0"
44
edition = "2021"
55

66
[dependencies]

src/cmd/new.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::{
88
types::{AnyError, EnterSpec, WorkSpec},
99
},
1010
};
11-
use colored::Colorize;
1211

1312
impl<'a> WorkspaceApi<'a> {
1413
pub async fn new(
@@ -113,15 +112,12 @@ impl<'a> WorkspaceApi<'a> {
113112
let mut cfg_builder = RoozCfg::default().from_cli_env(spec.clone());
114113

115114
match repo_config {
116-
Some(Ok(c)) => {
117-
log::debug!(".rooz.toml found in the repository and applied.");
115+
Some(c) => {
116+
log::debug!("Config file applied.");
118117
cfg_builder = cfg_builder.from_config(c.clone());
119118
}
120-
Some(Err(e)) => {
121-
eprintln!("{}\n{}", e, "WARNING: Ignoring the invalid .rooz.toml file from the repository".yellow());
122-
}
123119
None => {
124-
log::debug!(".rooz.toml not found in the repository");
120+
log::debug!("No valid config file found in the repository.");
125121
}
126122
}
127123

src/git.rs

+43-22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use colored::Colorize;
2+
13
use crate::{
24
api::{container, ExecApi, GitApi},
35
id,
@@ -32,7 +34,7 @@ impl<'a> ExecApi<'a> {
3234
container_id: &str,
3335
clone_dir: &str,
3436
file_format: FileFormat,
35-
) -> Result<(FileFormat, String), AnyError> {
37+
) -> Result<Option<RoozCfg>, AnyError> {
3638
let file_path = &format!("{}/.rooz.{}", clone_dir, file_format.to_string());
3739

3840
let config = self
@@ -51,7 +53,27 @@ impl<'a> ExecApi<'a> {
5153
]),
5254
)
5355
.await?;
54-
Ok((file_format, config))
56+
57+
if config.is_empty() {
58+
Ok(None)
59+
} else {
60+
match RoozCfg::from_string(config, file_format) {
61+
Ok(cfg) => Ok(Some(cfg)),
62+
Err(e) => {
63+
eprintln!(
64+
"{}\n{}",
65+
format!(
66+
"WARNING: Could not read repo config ({})",
67+
file_format.to_string()
68+
)
69+
.bold()
70+
.yellow(),
71+
e.to_string().yellow()
72+
);
73+
Ok(None)
74+
}
75+
}
76+
}
5577
}
5678
}
5779

@@ -63,7 +85,7 @@ impl<'a> GitApi<'a> {
6385
url: &str,
6486
workspace_key: &str,
6587
working_dir: &str,
66-
) -> Result<(Option<Result<RoozCfg, AnyError>>, GitCloneSpec), AnyError> {
88+
) -> Result<(Option<RoozCfg>, GitCloneSpec), AnyError> {
6789
let clone_dir = get_clone_dir(working_dir, url);
6890

6991
let clone_cmd = container::inject(
@@ -125,28 +147,27 @@ impl<'a> GitApi<'a> {
125147
.await?;
126148
};
127149

128-
let (file_format, rooz_cfg) = self
129-
.api
130-
.exec
131-
.read_rooz_config(container_id, &clone_dir, FileFormat::Toml)
132-
.await
133-
.or(self
134-
.api
135-
.exec
136-
.read_rooz_config(container_id, &clone_dir, FileFormat::Yaml)
137-
.await)?;
150+
let exec = &self.api.exec;
138151

139-
log::debug!("Repo config result: {}", &rooz_cfg);
152+
let rooz_cfg = if let Some(cfg) = exec
153+
.read_rooz_config(container_id, &clone_dir, FileFormat::Toml)
154+
.await?
155+
{
156+
log::debug!("Config file found (TOML)");
157+
Some(cfg)
158+
} else if let Some(cfg) = exec
159+
.read_rooz_config(container_id, &clone_dir, FileFormat::Yaml)
160+
.await?
161+
{
162+
log::debug!("Config file found (YAML)");
163+
Some(cfg)
164+
} else {
165+
log::debug!("No valid config file found");
166+
None
167+
};
140168

141169
self.api.container.remove(&container_id, true).await?;
142170

143-
Ok((
144-
if rooz_cfg.is_empty() {
145-
None
146-
} else {
147-
Some(RoozCfg::from_string(rooz_cfg, file_format))
148-
},
149-
GitCloneSpec { dir: clone_dir },
150-
))
171+
Ok((rooz_cfg, GitCloneSpec { dir: clone_dir }))
151172
}
152173
}

src/model/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub struct RoozCfg {
4343
pub sidecars: Option<HashMap<String, RoozSidecar>>,
4444
}
4545

46-
#[derive(Debug, Clone)]
46+
#[derive(Debug, Clone, Copy)]
4747
pub enum FileFormat {
4848
Toml,
4949
Yaml,

0 commit comments

Comments
 (0)