Skip to content

Commit

Permalink
Populate directory field in challenge config
Browse files Browse the repository at this point in the history
This field is used to check against the enabled/disabled challenges in the
deploy profile, and was not being set when parsed. This got removed in a
rebase somewhere(?) and broke the validate command. Now fixed!

Signed-off-by: Robert Detjens <[email protected]>
  • Loading branch information
detjensrobert committed Nov 9, 2024
1 parent d3ca47b commit 1f95079
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/configparser/challenge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,32 @@ pub fn parse_all() -> Vec<Result<ChallengeConfig, Error>> {
pub fn parse_one(path: &str) -> Result<ChallengeConfig> {
trace!("trying to parse {path}");

// remove 'challenge.yaml' from path
let chal_dir = Path::new(path)
// pop off leading `./` from SearchBuilder results
.strip_prefix("./")?
// remove last challenge.yaml
.parent()
.expect("could not extract path from search path");

// extract category from challenge path
let category = Path::new(path)
let category = chal_dir
.components()
.nth_back(2)
.nth_back(1)
.expect("could not find category from path")
.as_os_str()
.to_str()
.unwrap();

let parsed = Figment::new()
.merge(Yaml::file(path))
// merge in generated data from file path
.merge(Serialized::default("directory", chal_dir))
.merge(Serialized::default("category", category))
.extract()?;

trace!("got challenge config: {parsed:#?}");

Ok(parsed)
}

Expand All @@ -57,13 +70,10 @@ pub struct ChallengeConfig {
name: String,
author: String,
description: String,
category: String,

#[serde(default)]
directory: PathBuf,

#[serde(default)]
category: String,

#[serde(default = "default_difficulty")]
difficulty: i64,

Expand Down

0 comments on commit 1f95079

Please sign in to comment.