langtool: Add easy command to remove a key.

This commit is contained in:
Henrik Rydgård 2022-09-03 10:52:48 +02:00
parent dc86970098
commit 759dc25503
2 changed files with 28 additions and 10 deletions

View file

@ -76,9 +76,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
[[package]]
name = "libc"
version = "0.2.126"
version = "0.2.132"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836"
checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5"
[[package]]
name = "proc-macro-error"
@ -106,18 +106,18 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.40"
version = "1.0.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.20"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
]
@ -154,9 +154,9 @@ dependencies = [
[[package]]
name = "syn"
version = "1.0.98"
version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd"
checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
dependencies = [
"proc-macro2",
"quote",
@ -174,9 +174,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.1"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf"
[[package]]
name = "unicode-segmentation"

View file

@ -19,6 +19,7 @@ enum Command {
CommentUnknownLines {},
RemoveUnknownLines {},
MoveKey { old: String, new: String, key: String },
RemoveKey { section: String, key: String },
}
fn copy_missing_lines(reference_ini: &IniFile, target_ini: &mut IniFile) -> io::Result<()> {
@ -79,6 +80,20 @@ fn move_key(
Ok(())
}
fn remove_key(
target_ini: &mut IniFile,
section: &str,
key: &str,
) -> io::Result<()> {
// Insert any missing full sections.
if let Some(old_section) = target_ini.get_section_mut(section) {
let _ = old_section.remove_line(key);
} else {
println!("No section {}", section);
}
Ok(())
}
fn main() {
let opt = Opt::from_args();
@ -130,6 +145,9 @@ fn main() {
Command::MoveKey { ref old, ref new,ref key, } => {
move_key(&mut target_ini, &old, &new, &key).unwrap();
}
Command::RemoveKey { ref section, ref key } => {
remove_key(&mut target_ini, section, key).unwrap();
}
}
target_ini.write().unwrap();