@@ -7,7 +7,7 @@ use std::{
7
7
use anyhow:: { anyhow, Context , Result } ;
8
8
use clap:: Parser ;
9
9
use path_absolutize:: Absolutize ;
10
- use tokio:: { fs :: File , io :: AsyncReadExt } ;
10
+ use tokio;
11
11
12
12
use spin_loader:: local:: absolutize;
13
13
use spin_templates:: { RunOptions , Template , TemplateManager , TemplateVariantInfo } ;
@@ -178,17 +178,19 @@ impl FromStr for ParameterValue {
178
178
}
179
179
}
180
180
181
- async fn values_from_file ( file : impl AsRef < Path > ) -> Result < HashMap < String , String > > {
182
- let file = absolutize ( file) ?;
181
+ /// This function reads a file and parses it as TOML, then
182
+ /// returns the resulting hashmap of key-value pairs.
183
+ async fn values_from_file ( path : impl AsRef < Path > ) -> Result < HashMap < String , String > > {
184
+ // Get the absolute path of the file we're reading.
185
+ let path = absolutize ( path) ?;
183
186
184
- let mut buf = vec ! [ ] ;
185
- File :: open ( & file)
186
- . await ?
187
- . read_to_end ( & mut buf)
187
+ // Open the file.
188
+ let text = tokio:: fs:: read_to_string ( & path)
188
189
. await
189
- . with_context ( || anyhow ! ( "Cannot read values file from {:? }" , file ) ) ?;
190
+ . with_context ( || format ! ( "Failed to read text from values file { }" , path . display ( ) ) ) ?;
190
191
191
- toml:: from_slice ( & buf) . context ( "Failed to deserialize values file" )
192
+ // Parse the TOML file into a hashmap of values.
193
+ toml:: from_str ( & text) . context ( "Failed to deserialize values file" )
192
194
}
193
195
194
196
/// Merges values from file and values passed as command line options. CLI
0 commit comments