coliru

A minimal, flexible, dotfile installer
git clone https://git.ashermorgan.net/coliru/
Log | Files | Refs | README

commit 5ed3ac2a02465ed68ab601609f24efe94ba6e1af
parent 15790b34bd6957e972a179b953d72eb8e7758c3e
Author: Asher Morgan <59518073+ashermorgan@users.noreply.github.com>
Date:   Thu, 20 Jun 2024 13:11:17 -0700

Implement execute_manifest_file function

Diffstat:
Msrc/core.rs | 19++++++++++++++-----
Msrc/main.rs | 6++----
2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/core.rs b/src/core.rs @@ -1,17 +1,26 @@ use std::env::set_current_dir; -use super::manifest; -use super::tags; +use std::path::Path; +use super::manifest::{CopyOptions, Manifest, parse_manifest_file}; +use super::tags::tags_match; use super::utils::copy_file; +/// Execute the steps in a coliru manifest file according to a set of tag rules +pub fn execute_manifest_file(path: &Path, tag_rules: Vec<String>) { + match parse_manifest_file(path) { + Ok(manifest) => execute_manifest(manifest, tag_rules), + Err(why) => eprintln!("Error: {}", why), + }; +} + /// Execute the steps in a coliru manifest according to a set of tag rules -pub fn execute_manifest(manifest: manifest::Manifest, rules: Vec<String>) { +fn execute_manifest(manifest: Manifest, tag_rules: Vec<String>) { if let Err(why) = set_current_dir(manifest.base_dir) { eprintln!("Error: {}", why); return; } for (i, step) in manifest.steps.iter().enumerate() { - if tags::tags_match(&rules, &step.tags) { + if tags_match(&tag_rules, &step.tags) { println!("Step {}:", i+1); execute_copies(&step.copy); } else { @@ -21,7 +30,7 @@ pub fn execute_manifest(manifest: manifest::Manifest, rules: Vec<String>) { } /// Execute the copy commands specified in a coliru manifest step -fn execute_copies(copies: &[manifest::CopyOptions]) { +fn execute_copies(copies: &[CopyOptions]) { for copy in copies { println!(" Copy {} to {}", copy.src, copy.dst); if let Err(why) = copy_file(&copy.src, &copy.dst) { diff --git a/src/main.rs b/src/main.rs @@ -8,8 +8,6 @@ use clap::Parser; fn main() { let args = cli::CLI::parse(); - match manifest::parse_manifest_file(&std::path::Path::new(&args.manifest)) { - Ok(manifest) => core::execute_manifest(manifest, args.tag_rules), - Err(why) => eprintln!("Error: {}", why), - }; + let manifest_path = std::path::Path::new(&args.manifest); + core::execute_manifest_file(&manifest_path, args.tag_rules); }