commit 0d6a3817ba32d91452e51d0de55c9f4b67ed0d9a
parent 66b677bd2bdd923ef0b70083e00686f3ede7cca7
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date: Fri, 21 Jun 2024 10:58:35 -0700
Implement run command in manifest parser
Diffstat:
6 files changed, 47 insertions(+), 26 deletions(-)
diff --git a/.editorconfig b/.editorconfig
@@ -10,3 +10,6 @@ indent_size = 4
insert_final_newline = true
max_line_length = 80
trim_trailing_whitespace = true
+
+[*.{yml,yaml}]
+indent_size = 2
diff --git a/examples/2.yml b/examples/2.yml
@@ -1,14 +0,0 @@
-# Valid manifest
-
-steps:
- - link:
- - src: foo
- dst: ~/foo
- - src: bar
- dst: ~/test/bar
- tags: [ a, b ]
-
- - copy:
- - src: baz
- dst: /baz
- # tags default to []
diff --git a/examples/baz b/examples/baz
@@ -1 +1,3 @@
-baz!
+#!/usr/bin/sh
+
+echo 'baz!' > ~/baz
diff --git a/examples/1.yml b/examples/invalid.yml
diff --git a/examples/manifest.yml b/examples/manifest.yml
@@ -0,0 +1,16 @@
+# Valid manifest
+
+steps:
+ - copy:
+ - src: foo
+ dst: /foo
+ link:
+ - src: foo
+ dst: ~/foo
+ - src: bar
+ dst: ~/test/bar
+ tags: [ a, b ]
+
+ - run:
+ - src: baz
+ tags: [ c ]
diff --git a/src/manifest.rs b/src/manifest.rs
@@ -10,6 +10,11 @@ pub struct CopyLinkOptions {
}
#[derive(Debug, PartialEq, Deserialize)]
+pub struct RunOptions {
+ pub src: String,
+}
+
+#[derive(Debug, PartialEq, Deserialize)]
pub struct Step {
#[serde(default)]
pub copy: Vec<CopyLinkOptions>,
@@ -18,6 +23,9 @@ pub struct Step {
pub link: Vec<CopyLinkOptions>,
#[serde(default)]
+ pub run: Vec<RunOptions>,
+
+ #[serde(default)]
pub tags: Vec<String>,
}
@@ -53,14 +61,14 @@ mod tests {
#[test]
fn parse_manifest_file_missing() {
let expected = "No such file or directory (os error 2)";
- let actual = parse_manifest_file(Path::new("examples/0.yml"));
+ let actual = parse_manifest_file(Path::new("examples/missing.yml"));
assert_eq!(actual, Err(String::from(expected)));
}
#[test]
fn parse_manifest_file_invalid() {
let expected = "steps[1].copy[0]: missing field `src` at line 12 column 7";
- let actual = parse_manifest_file(Path::new("examples/1.yml"));
+ let actual = parse_manifest_file(Path::new("examples/invalid.yml"));
assert_eq!(actual, Err(String::from(expected)));
}
@@ -69,33 +77,39 @@ mod tests {
let expected = Manifest {
steps: vec![
Step {
- copy: vec![],
+ copy: vec![
+ CopyLinkOptions {
+ src: String::from("foo"),
+ dst: String::from("/foo"),
+ },
+ ],
link: vec![
- CopyLinkOptions{
+ CopyLinkOptions {
src: String::from("foo"),
dst: String::from("~/foo"),
},
- CopyLinkOptions{
+ CopyLinkOptions {
src: String::from("bar"),
dst: String::from("~/test/bar"),
},
],
+ run: vec![],
tags: vec![String::from("a"), String::from("b")],
},
Step {
- copy: vec![
- CopyLinkOptions{
+ copy: vec![],
+ link: vec![],
+ run: vec![
+ RunOptions {
src: String::from("baz"),
- dst: String::from("/baz"),
},
],
- link: vec![],
- tags: vec![],
+ tags: vec![String::from("c")],
}
],
base_dir: PathBuf::from("examples"),
};
- let actual = parse_manifest_file(Path::new("examples/2.yml"));
+ let actual = parse_manifest_file(Path::new("examples/manifest.yml"));
assert_eq!(actual, Ok(expected));
}
}