diff --git a/front/Cargo.toml b/front/Cargo.toml index d01670b..db31328 100644 --- a/front/Cargo.toml +++ b/front/Cargo.toml @@ -16,4 +16,7 @@ name = "alejandra_front" repository = "https://github.com/kamadorueda/alejandra" version = "0.3.1" +[profile.release] +lto = true + [workspace] diff --git a/src/alejandra_cli/src/cli.rs b/src/alejandra_cli/src/cli.rs index 8e60c4d..73aa6bb 100644 --- a/src/alejandra_cli/src/cli.rs +++ b/src/alejandra_cli/src/cli.rs @@ -3,10 +3,18 @@ pub fn parse(args: Vec) -> clap::ArgMatches { .about("The Uncompromising Nix Code Formatter.") .version(alejandra_engine::version::VERSION) .arg( - clap::Arg::new("paths") + clap::Arg::new("include") .help("Files or directories, or none to format stdin.") .multiple_values(true), ) + .arg( + clap::Arg::new("exclude") + .short('e') + .help("Files or directories to exclude from formatting.") + .long("exclude") + .multiple_occurrences(true) + .takes_value(true), + ) .term_width(80) .after_help(indoc::indoc!( // Let's just use the same sorting as on GitHub @@ -240,12 +248,12 @@ pub fn tui( .bg(tui::style::Color::Black) .add_modifier(tui::style::Modifier::ITALIC), ) - .percent( - (100 * (paths_changed - + paths_unchanged - + paths_with_errors) - / paths_to_format) as u16, - ) + .percent(if paths_to_format == 0 { + 100 + } else { + 100 * (paths_changed + paths_unchanged + paths_with_errors) + / paths_to_format + } as u16) .style( tui::style::Style::default() .bg(tui::style::Color::Black) diff --git a/src/alejandra_cli/src/find.rs b/src/alejandra_cli/src/find.rs index 204d99b..77e8f12 100644 --- a/src/alejandra_cli/src/find.rs +++ b/src/alejandra_cli/src/find.rs @@ -1,11 +1,17 @@ -pub fn nix_files(paths: Vec<&str>) -> Vec { +pub fn nix_files(include: Vec<&str>, exclude: Vec<&str>) -> Vec { + let include: std::collections::HashSet = + include.iter().flat_map(nix_files_in_path).collect(); + let exclude: std::collections::HashSet = + exclude.iter().flat_map(nix_files_in_path).collect(); + let mut paths: Vec = - paths.iter().flat_map(nix_files_in_path).collect(); + include.difference(&exclude).map(|path| path.clone()).collect(); + paths.sort(); paths } -fn nix_files_in_path(path: &&str) -> Vec { +fn nix_files_in_path(path: &&str) -> std::collections::HashSet { walkdir::WalkDir::new(path) .into_iter() .filter_entry(is_nix_file_or_dir) diff --git a/src/alejandra_cli/src/main.rs b/src/alejandra_cli/src/main.rs index 97edebe..5aaf90a 100644 --- a/src/alejandra_cli/src/main.rs +++ b/src/alejandra_cli/src/main.rs @@ -3,10 +3,16 @@ fn main() -> std::io::Result<()> { let config = alejandra_engine::config::Config::default(); - match matches.values_of("paths") { - Some(paths) => { + match matches.values_of("include") { + Some(include) => { + let include = include.collect(); + let exclude = match matches.values_of("exclude") { + Some(exclude) => exclude.collect(), + None => vec![], + }; + let paths: Vec = - alejandra_cli::find::nix_files(paths.collect()); + alejandra_cli::find::nix_files(include, exclude); if atty::is(atty::Stream::Stderr) && atty::is(atty::Stream::Stdin)