Changeset 5bd9641 in gignore
- Timestamp:
- 19 Feb 2026, 22:16:46 (2 months ago)
- Branches:
- file_locations, help, logging, man, multi_arg, trunk
- Children:
- eb42226
- Parents:
- d5c0cff
- Files:
-
- 1 added
- 3 edited
-
Cargo.toml (modified) (1 diff)
-
src/main.rs (modified) (2 diffs)
-
src/template.rs (modified) (4 diffs)
-
temp.txt (added)
Legend:
- Unmodified
- Added
- Removed
-
Cargo.toml
rd5c0cff r5bd9641 6 6 [dependencies] 7 7 clap = { version = "4.5.53", features = ["derive"] } 8 home = "0.5.12"9 8 anyhow = "1.0.100" 10 9 serde = { version = "1.0.228", features = ["derive"] } -
src/main.rs
rd5c0cff r5bd9641 184 184 open_truncate(".gitignore".as_ref()).context("cannot open `.gitignore` in truncate mode")?.write_all(b"").context("cannot write to `.gitignore`")?; 185 185 186 // Re-add lines to file, without [PATH].186 // Re-add lines to file, without PATH. 187 187 for line in lines { 188 188 open_append(".gitignore".as_ref()).context("cannot open `.gitignore` in append mode")? … … 219 219 } 220 220 } => { 221 template::add(&template::Template::new(source_file.as_ref(), name, *append)).context("cannot add template")?; 221 let x = template::Template::new(source_file.as_ref(), name, *append); 222 223 template::add(x).context("cannot add template")?; 222 224 223 225 Ok(()) -
src/template.rs
rd5c0cff r5bd9641 4 4 PathBuf, 5 5 }, 6 io:: Write,6 io::{self, Write}, 7 7 fs, 8 8 os::unix::fs::MetadataExt, 9 process, 9 10 }; 10 11 … … 41 42 &self.source_file 42 43 } 44 fn change_source_file<T: AsRef<Path>>(&mut self, new: T) { 45 self.source_file = new.as_ref().to_owned(); 46 } 43 47 pub(crate) fn get_name(&self) -> &str { 44 48 &self.name … … 117 121 } 118 122 119 pub(crate) fn add( template: &Template) -> Result<()> {123 pub(crate) fn add(mut template: Template) -> Result<()> { 120 124 if !fs::exists(template.get_source_file()).context(format!("cannot search for `{}`", template.get_name()))? { 121 125 return Err(Error::msg(format!("The source file specified, `{}`, does not exist.", template.get_source_file().display()))); 122 126 } 123 127 128 if (&*(template.get_source_file().to_string_lossy())).split_terminator('.').nth(2) != Some("ggnr") { 129 eprintln!("WARNING: specified source file, `{}`, does not have the file extension for gignore templates (`.ggnr`). Continue anyway? [y/N]", template.get_source_file().display()); 130 131 let mut buf = String::new(); 132 io::stdin() 133 .read_line(&mut buf) 134 .context("cannot read from stdin")?; 135 136 match &*buf.to_lowercase().trim() { 137 "y" => { eprintln!("Continuing..."); }, 138 _ => { 139 eprintln!("User denied operation. Exiting."); 140 process::exit(0); 141 }, 142 } 143 }; 144 124 145 let new_template_path = format!("/usr/lib/gignore/{}", template.get_source_file().display()); 146 147 if fs::exists(&new_template_path).context(format!("cannot search for `{new_template_path}`"))? { 148 eprintln!("WARNING: the file `{new_template_path}` already exists. Overwrite it? [y/N]"); 149 150 let mut buf = String::new(); 151 io::stdin() 152 .read_line(&mut buf) 153 .context("cannot read from stdin")?; 154 155 match &*buf.to_lowercase().trim() { 156 "y" => { 157 eprintln!("Continuing..."); 158 159 fs::remove(&new_template_path). 160 }, 161 _ => { 162 eprintln!("User denied operation. Exiting."); 163 process::exit(0); 164 }, 165 } 166 }; 125 167 126 168 drop( … … 142 184 } 143 185 144 fs::remove_file(template.get_source_file()).context(format!("cannot remove `{}`", template.get_source_file().display()))?;145 146 186 if find_name(template.get_name()).context("cannot search for name in template library")?.is_some() { 147 187 return Err(Error::msg(format!("A template with the name `{}` already exists!", template.get_name()))); 148 188 } 189 template.change_source_file(new_template_path); 190 149 191 template.save().context("cannot save template")?; 150 192
Note:
See TracChangeset
for help on using the changeset viewer.
