Skip to content

Commit 0a83323

Browse files
committed
Support single string provide include as same as bare string
Found this missing case when writing docs. Specifiying `include:` as a single string should be equivalent to specifying a bare string, which is already treated as a one-element array. Renaming only happens when as: is present, and we should support the `include:` single string like a 1-element array, like the bare string case. Signed-off-by: Robert Detjens <github@detjens.dev>
1 parent ae8c0b1 commit 0a83323

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/builder/artifacts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub async fn extract_asset(
4141
let extracted_files = match provide {
4242
// Repo file paths are relative to the challenge directory, so prepend chal dir
4343

44+
// No action necessary, return path as-is
45+
ProvideConfig::FromRepoSingle { file } => Ok(vec![chal.directory.join(file)]),
4446
// No action necessary, return path as-is
4547
ProvideConfig::FromRepo { files } => {
4648
Ok(files.iter().map(|f| chal.directory.join(f)).collect_vec())

src/configparser/challenge.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ enum ProvideConfig {
262262
/// Upload file(s) as-is.
263263
/// Single or multiple files with no as: or from:
264264
/// Default if only a string is given.
265+
FromRepoSingle {
266+
#[serde(rename = "include")]
267+
file: PathBuf,
268+
},
265269
FromRepo {
266270
#[serde(rename = "include")]
267271
files: Vec<PathBuf>,
@@ -315,8 +319,8 @@ enum ProvideConfig {
315319
impl FromStr for ProvideConfig {
316320
type Err = Void;
317321
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
318-
Ok(ProvideConfig::FromRepo {
319-
files: vec![PathBuf::from(s)],
322+
Ok(ProvideConfig::FromRepoSingle {
323+
file: PathBuf::from(s),
320324
})
321325
}
322326
}

src/tests/parsing/challenges.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,8 @@ fn challenge_provide() {
242242
provide:
243243
- foo.txt
244244
245+
- include: foo2.txt
246+
245247
- include:
246248
- bar.txt
247249
- baz.txt
@@ -275,8 +277,11 @@ fn challenge_provide() {
275277
assert_eq!(
276278
chals[0].provide,
277279
vec![
278-
ProvideConfig::FromRepo {
279-
files: vec!["foo.txt".into()]
280+
ProvideConfig::FromRepoSingle {
281+
file: "foo.txt".into()
282+
},
283+
ProvideConfig::FromRepoSingle {
284+
file: "foo2.txt".into()
280285
},
281286
ProvideConfig::FromRepo {
282287
files: vec!["bar.txt".into(), "baz.txt".into()]

0 commit comments

Comments
 (0)