Compare commits
1 Commits
5f44cb2f4e
...
5570497d62
| Author | SHA1 | Date | |
|---|---|---|---|
| 5570497d62 |
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -61,12 +61,6 @@ dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.97"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dcfed56ad506cb2c684a14971b8861fdc3baaaae314b9e5f9bb532cbe3ba7a4f"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.34"
|
||||
@@ -390,7 +384,6 @@ dependencies = [
|
||||
name = "skubelb"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
"dir-diff",
|
||||
"env_logger",
|
||||
|
||||
@@ -4,7 +4,6 @@ version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.97"
|
||||
clap = { version = "4.5.34", features = ["derive"] }
|
||||
dir-diff = "0.3.3"
|
||||
env_logger = "0.11.7"
|
||||
|
||||
@@ -12,19 +12,13 @@ use rewriter::Rewriter;
|
||||
#[derive(Parser, Debug)]
|
||||
#[command(version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// The needle that will be replaced. Anytime a line
|
||||
/// is encountered with this needle, the line is dropped
|
||||
/// and instead N lines (one per replacement) is added to
|
||||
/// the output.
|
||||
/// Name of the person to greet
|
||||
#[arg(short, long)]
|
||||
rewrite_string: String,
|
||||
|
||||
/// The folder which contains the templates that
|
||||
/// will be be searched for the needle.
|
||||
#[arg(short, long)]
|
||||
source_folder: String,
|
||||
|
||||
/// Where to write the replaced lines.
|
||||
#[arg(short, long)]
|
||||
dest_folder: String,
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
use anyhow::Result;
|
||||
use std::collections::HashSet;
|
||||
use std::path::Path;
|
||||
use std::{
|
||||
fs::{self, File},
|
||||
io::{BufReader, prelude::*},
|
||||
io::{self, BufReader, prelude::*},
|
||||
};
|
||||
|
||||
pub struct Rewriter {
|
||||
@@ -27,7 +26,7 @@ impl Rewriter {
|
||||
self.replacements.remove(replacement);
|
||||
}
|
||||
|
||||
pub fn rewrite_folder(&self, src: &str, dst: &str) -> Result<()> {
|
||||
pub fn rewrite_folder(&self, src: &str, dst: &str) -> Result<(), io::Error> {
|
||||
// Make sure we are deterministic; construct a list of strings and sort
|
||||
// them
|
||||
let mut replacements: Vec<String> = self.replacements.iter().map(|s| s.clone()).collect();
|
||||
@@ -44,7 +43,7 @@ impl Rewriter {
|
||||
// First, calculate the 'relative' path after we trim the
|
||||
// the src prefix, then join that with the dst prefix
|
||||
let src_path = entry.path();
|
||||
let src_part_path = src_path.strip_prefix(&src)?;
|
||||
let src_part_path = src_path.strip_prefix(&src).unwrap();
|
||||
let dst_path = dst_base.join(src_part_path);
|
||||
|
||||
if metadata.is_dir() {
|
||||
@@ -97,7 +96,9 @@ mod tests {
|
||||
#[test]
|
||||
fn basic_test() {
|
||||
let testdata = TempDir::new("").unwrap();
|
||||
TEST_FILES.extract(testdata.path()).unwrap();
|
||||
TEST_FILES
|
||||
.extract(testdata.path())
|
||||
.unwrap();
|
||||
let src = testdata.path().join("testsrc");
|
||||
let dst = TempDir::new("").unwrap();
|
||||
|
||||
@@ -114,8 +115,6 @@ mod tests {
|
||||
.unwrap();
|
||||
|
||||
// Validate that everything matches
|
||||
assert!(
|
||||
dir_diff::is_different(testdata.path().join("testdst"), dst.path()).unwrap() == false
|
||||
);
|
||||
assert!(dir_diff::is_different(testdata.path().join("testdst"), dst.path()).unwrap() == false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user