Skip to content

Commit 51869c2

Browse files
authored
Merge pull request #1052 from cardoso/main
Update toml dependency to 0.6
2 parents c81ca18 + cba9547 commit 51869c2

File tree

3 files changed

+77
-23
lines changed

3 files changed

+77
-23
lines changed

Cargo.lock

Lines changed: 65 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ spin-templates = { path = "crates/templates" }
5454
spin-trigger = { path = "crates/trigger" }
5555
tempfile = "3.3.0"
5656
tokio = { version = "1.23", features = [ "full" ] }
57-
toml = "0.5"
57+
toml = "0.6"
5858
tracing = { workspace = true }
5959
tracing-subscriber = { version = "0.3.7", features = [ "env-filter" ] }
6060
url = "2.2.2"

src/commands/new.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
use anyhow::{anyhow, Context, Result};
88
use clap::Parser;
99
use path_absolutize::Absolutize;
10-
use tokio::{fs::File, io::AsyncReadExt};
10+
use tokio;
1111

1212
use spin_loader::local::absolutize;
1313
use spin_templates::{RunOptions, Template, TemplateManager, TemplateVariantInfo};
@@ -178,17 +178,19 @@ impl FromStr for ParameterValue {
178178
}
179179
}
180180

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)?;
183186

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)
188189
.await
189-
.with_context(|| anyhow!("Cannot read values file from {:?}", file))?;
190+
.with_context(|| format!("Failed to read text from values file {}", path.display()))?;
190191

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")
192194
}
193195

194196
/// Merges values from file and values passed as command line options. CLI

0 commit comments

Comments
 (0)