1
+ use colored:: Colorize ;
2
+
1
3
use crate :: {
2
4
api:: { container, ExecApi , GitApi } ,
3
5
id,
@@ -32,7 +34,7 @@ impl<'a> ExecApi<'a> {
32
34
container_id : & str ,
33
35
clone_dir : & str ,
34
36
file_format : FileFormat ,
35
- ) -> Result < ( FileFormat , String ) , AnyError > {
37
+ ) -> Result < Option < RoozCfg > , AnyError > {
36
38
let file_path = & format ! ( "{}/.rooz.{}" , clone_dir, file_format. to_string( ) ) ;
37
39
38
40
let config = self
@@ -51,7 +53,27 @@ impl<'a> ExecApi<'a> {
51
53
] ) ,
52
54
)
53
55
. 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
+ }
55
77
}
56
78
}
57
79
@@ -63,7 +85,7 @@ impl<'a> GitApi<'a> {
63
85
url : & str ,
64
86
workspace_key : & str ,
65
87
working_dir : & str ,
66
- ) -> Result < ( Option < Result < RoozCfg , AnyError > > , GitCloneSpec ) , AnyError > {
88
+ ) -> Result < ( Option < RoozCfg > , GitCloneSpec ) , AnyError > {
67
89
let clone_dir = get_clone_dir ( working_dir, url) ;
68
90
69
91
let clone_cmd = container:: inject (
@@ -125,28 +147,27 @@ impl<'a> GitApi<'a> {
125
147
. await ?;
126
148
} ;
127
149
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 ;
138
151
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
+ } ;
140
168
141
169
self . api . container . remove ( & container_id, true ) . await ?;
142
170
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 } ) )
151
172
}
152
173
}
0 commit comments