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