explain/
main.rs

1use {
2    clap::Parser,
3    codesort::*,
4    std::path::PathBuf,
5};
6
7/// dump to stdout informations about the sorting of the given file
8/// at the specified location
9#[derive(Debug, Parser)]
10#[command(about, version)]
11pub struct Args {
12    /// line number (1-based) around which to sort
13    #[clap(long)]
14    pub sort_around: Option<LineNumber>,
15
16    /// Path to the file(s)
17    pub path: PathBuf,
18}
19
20fn main() -> CsResult<()> {
21    let args = Args::parse();
22    let loc_list = LocList::read_file(&args.path, Language::Rust)?;
23    let Some(sort_around) = args.sort_around else {
24        loc_list.print_debug(" WHOLE FILE ");
25        return Ok(());
26    };
27    let focused = loc_list.focus_around_line_number(sort_around)?;
28    focused.print_debug();
29    let blocks = focused.clone().focus.into_blocks();
30    for (i, block) in blocks.iter().enumerate() {
31        block.print_debug(&format!(" BLOCK {i} "));
32    }
33    let loc_list = focused.sort();
34    println!("------------ RESULT ------------");
35    print!("{}", loc_list);
36    Ok(())
37}