Add basic functionality
This commit is contained in:
@@ -6,3 +6,4 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
clap = {version = "3.1.17", features = ["derive"]}
|
44
src/main.rs
44
src/main.rs
@@ -1,5 +1,45 @@
|
|||||||
fn main() {
|
use std::fs::{File, read_to_string};
|
||||||
println!("Hello, world!");
|
use std::io::{BufWriter, Error, Write};
|
||||||
|
use clap::Parser;
|
||||||
|
|
||||||
|
fn main() -> Result<(), Error> {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
|
let wordlist = read_to_string(args.filepath)?;
|
||||||
|
let mut list: Vec<&str> = wordlist.split_ascii_whitespace().collect();
|
||||||
|
|
||||||
|
let lowerbound = list.iter().position(|&x| x.contains("\\begin{acronym}"));
|
||||||
|
let upperbound = list.iter().position(|&x| x.contains("\\end{acronym}"));
|
||||||
|
|
||||||
|
match (lowerbound, upperbound) {
|
||||||
|
(Some(lower), Some(upper)) => {
|
||||||
|
println!("Sort range {}-{}", lower, upper);
|
||||||
|
sort_range(lower + 1, upper, &mut list)
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
println!("No bounds found.");
|
||||||
|
()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut writer = BufWriter::new(File::create(args.filepath)?);
|
||||||
|
writer.write(list.join("\n").as_bytes())?;
|
||||||
|
println!("Done.");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sort_range(lowerbound: usize, upperbound: usize, list: &mut Vec<&str>) {
|
||||||
|
list[lowerbound..upperbound].sort_unstable();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Sorts the acronym block of a .tex file
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[clap(author, version, about, long_about = None)]
|
||||||
|
struct Args {
|
||||||
|
/// The filepath to the .tex file
|
||||||
|
#[clap(short, long)]
|
||||||
|
filepath: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user