Compare commits
1 Commits
5570497d62
...
5f44cb2f4e
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f44cb2f4e |
7
Cargo.lock
generated
7
Cargo.lock
generated
@@ -61,6 +61,12 @@ 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"
|
||||||
@@ -384,6 +390,7 @@ 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,6 +4,7 @@ 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,13 +12,19 @@ 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 {
|
||||||
/// Name of the person to greet
|
/// 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.
|
||||||
#[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,8 +1,9 @@
|
|||||||
|
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::{self, BufReader, prelude::*},
|
io::{BufReader, prelude::*},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct Rewriter {
|
pub struct Rewriter {
|
||||||
@@ -26,7 +27,7 @@ impl Rewriter {
|
|||||||
self.replacements.remove(replacement);
|
self.replacements.remove(replacement);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn rewrite_folder(&self, src: &str, dst: &str) -> Result<(), io::Error> {
|
pub fn rewrite_folder(&self, src: &str, dst: &str) -> Result<()> {
|
||||||
// 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();
|
||||||
@@ -43,7 +44,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).unwrap();
|
let src_part_path = src_path.strip_prefix(&src)?;
|
||||||
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() {
|
||||||
@@ -96,9 +97,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn basic_test() {
|
fn basic_test() {
|
||||||
let testdata = TempDir::new("").unwrap();
|
let testdata = TempDir::new("").unwrap();
|
||||||
TEST_FILES
|
TEST_FILES.extract(testdata.path()).unwrap();
|
||||||
.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();
|
||||||
|
|
||||||
@@ -115,6 +114,8 @@ mod tests {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// Validate that everything matches
|
// 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