Skip to content

Commit

Permalink
refactor: a yaml file may now not have the tasks element
Browse files Browse the repository at this point in the history
close #2
  • Loading branch information
MoskalykA committed Jul 19, 2023
1 parent 5c9860f commit dff3cf3
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct Task {

#[derive(Debug, PartialEq, Serialize, Deserialize)]
struct Options {
tasks: HashMap<String, Task>,
tasks: Option<HashMap<String, Task>>,
files: Option<Vec<String>>,
}

Expand All @@ -47,20 +47,22 @@ fn read_file(file_name: String, register: &mut HashMap<String, Vec<Commands>>) {
}
}

for (name, task) in options.tasks {
if let Some(register_commands) = register.get_mut(&name) {
register_commands.push(Commands {
path: path.clone(),
task,
});
} else {
register.insert(
name,
vec![Commands {
if let Some(tasks) = options.tasks {
for (name, task) in tasks {
if let Some(register_commands) = register.get_mut(&name) {
register_commands.push(Commands {
path: path.clone(),
task,
}],
);
});
} else {
register.insert(
name,
vec![Commands {
path: path.clone(),
task,
}],
);
}
}
}

Expand Down

0 comments on commit dff3cf3

Please # to comment.