don't require existing override
This commit is contained in:
parent
7bce1e7a6e
commit
80ff0b36cb
5 changed files with 120 additions and 191 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -13,6 +13,8 @@ use fs_err::os::unix::fs::OpenOptionsExt;
|
|||
fn main_wrapped() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
|
||||
let args = append_override::Parser::parse();
|
||||
|
||||
dbg!(&args);
|
||||
|
||||
let success = append_override::CLI_ENABLE_COLOR.set(match args.color {
|
||||
ColorChoice::Always => true,
|
||||
ColorChoice::Auto => io::stdin().is_terminal(),
|
||||
|
|
@ -33,6 +35,7 @@ fn main_wrapped() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
|
|||
|
||||
// Get what file that thing is defined in.
|
||||
let def_path = append_override::get_where(&args.name, &filepath)?;
|
||||
dbg!(&def_path);
|
||||
let def_path = Arc::from(def_path);
|
||||
let mut opts = File::options();
|
||||
opts.read(true)
|
||||
|
|
@ -41,22 +44,19 @@ fn main_wrapped() -> Result<(), Box<dyn StdError + Send + Sync + 'static>> {
|
|||
.custom_flags(libc::O_CLOEXEC);
|
||||
let source_file = SourceFile::open_from(Arc::clone(&def_path), opts)?;
|
||||
|
||||
let (pri, last_def_line) = append_override::get_highest_prio(&args.name, source_file.clone())?;
|
||||
let pri = append_override::get_highest_prio(&args.name, source_file.clone())?;
|
||||
let new_pri = pri - 1;
|
||||
|
||||
eprintln!("{last_def_line}");
|
||||
|
||||
let new_pri_line = append_override::get_next_prio_line(
|
||||
source_file.clone(),
|
||||
args.name.into(),
|
||||
last_def_line.clone(),
|
||||
new_pri,
|
||||
args.value.into(),
|
||||
)?;
|
||||
|
||||
eprintln!("new_pri_line={new_pri_line}");
|
||||
|
||||
append_override::write_next_prio(source_file, last_def_line, new_pri_line.text())?;
|
||||
append_override::write_next_prio(source_file, new_pri_line)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue