Skip to content

Commit

Permalink
refactor: file-config is public
Browse files Browse the repository at this point in the history
  • Loading branch information
attakei committed Mar 17, 2024
1 parent f935d39 commit 768b9cb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ pub fn update(base_config: &Config, new_version: &Version) -> Result<()> {
let search_text = Tera::one_off(&f.search, &ctx, true).unwrap();
let replace_text = Tera::one_off(&f.replace, &ctx, true).unwrap();
let mut new_text: Vec<String> = Vec::new();
for line in read_to_string(f.get_path()).unwrap().split("\n") {
for line in read_to_string(&f.path).unwrap().split("\n") {
if line == search_text {
new_text.push(replace_text.to_string())
} else {
new_text.push(line.to_string())
}
}
let mut out = File::create(f.get_path())?;
let mut out = File::create(&f.path)?;
let _ = out.write(new_text.join("\n").as_bytes());
}
println!("Updated!!");
Expand Down
2 changes: 1 addition & 1 deletion src/commands/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub(crate) fn execute(_args: &Arguments) -> Result<()> {
println!("# Replace targets");
println!();
for f in config_data.get_files() {
println!("- {}", f.get_path())
println!("- {}", f.path.to_str().unwrap())
}
// Display infomation data.
Ok(())
Expand Down
8 changes: 1 addition & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Config {

#[derive(Clone, Serialize, Deserialize)]
pub struct FileConfig {
path: String,
pub path: PathBuf,
pub search: String,
pub replace: String,
}
Expand All @@ -35,12 +35,6 @@ impl Config {
}
}

impl FileConfig {
pub fn get_path(&self) -> &String {
&self.path
}
}

/**
* Return path of configuration file by inner rule.
*/
Expand Down

0 comments on commit 768b9cb

Please sign in to comment.