Skip to content

Commit 0cfe037

Browse files
author
Nichol Yip
committed
Fixed typo in opentimelineio.spk.yaml
Added render logic to linting command that caused some packages to return an error without it. Signed-off-by: Nichol Yip <[email protected]>
1 parent deb49e4 commit 0cfe037

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

crates/spk-cli/group4/src/cmd_lint.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use clap::Args;
99
use colored::Colorize;
1010
use spk_cli_common::{flags, CommandArgs, Run};
1111
use spk_schema::v0::Spec;
12-
use spk_schema::{AnyIdent, Error, LintedItem};
12+
use spk_schema::{AnyIdent, LintedItem, SpecTemplate, Template, TemplateExt};
1313

1414
/// Validate spk yaml files
1515
#[derive(Args)]
@@ -24,20 +24,14 @@ pub struct Lint {
2424
#[async_trait::async_trait]
2525
impl Run for Lint {
2626
async fn run(&mut self) -> Result<i32> {
27-
// let options = self.options.get_options()?;
2827
let mut out = 0;
28+
let options = self.options.get_options()?;
2929
for spec in self.packages.iter() {
30-
let file_path = spec
31-
.canonicalize()
32-
.map_err(|err| Error::InvalidPath(spec.to_owned(), err))?;
33-
let file = std::fs::File::open(&file_path)
34-
.map_err(|err| Error::FileOpenError(file_path.to_owned(), err))?;
35-
let rdr = std::io::BufReader::new(file);
30+
let yaml = SpecTemplate::from_file(spec).and_then(|t| t.render_lint(&options))?;
31+
let lints: std::result::Result<LintedItem<Spec<AnyIdent>>, serde_yaml::Error> =
32+
serde_yaml::from_str(&yaml);
3633

37-
let result: std::result::Result<LintedItem<Spec<AnyIdent>>, serde_yaml::Error> =
38-
serde_yaml::from_reader(rdr);
39-
40-
match result {
34+
match lints {
4135
Ok(s) => match s.lints.is_empty() {
4236
true => println!("{} {}", "OK".green(), spec.display()),
4337
false => {

crates/spk-schema/src/spec.rs

+5
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ impl Template for SpecTemplate {
163163
.map_err(Error::InvalidTemplate)?;
164164
Ok(SpecRecipe::from_yaml(rendered)?)
165165
}
166+
167+
fn render_lint(&self, options: &OptionMap) -> Result<String> {
168+
let data = super::TemplateData::new(options);
169+
spk_schema_liquid::render_template(&self.template, &data).map_err(Error::InvalidTemplate)
170+
}
166171
}
167172

168173
impl TemplateExt for SpecTemplate {

crates/spk-schema/src/template.rs

+3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ pub trait Template: Named + Sized {
1919

2020
/// Render this template with the provided values.
2121
fn render(&self, options: &OptionMap) -> Result<Self::Output>;
22+
23+
/// Render this template but return the rendered string instead.
24+
fn render_lint(&self, options: &OptionMap) -> Result<String>;
2225
}
2326

2427
pub trait TemplateExt: Template {

packages/opentimelineio/opentimelineio.spk.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ install:
3232
- pkg: python
3333
fromBuildEnv: Binary
3434

35-
componenents:
35+
components:
3636
- name: run
3737
files:
3838
- /bin/

0 commit comments

Comments
 (0)