mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 04:27:45 +00:00
feat: --exclude flag
This commit is contained in:
parent
e489195b02
commit
eb7c058318
4 changed files with 36 additions and 13 deletions
|
@ -16,4 +16,7 @@ name = "alejandra_front"
|
||||||
repository = "https://github.com/kamadorueda/alejandra"
|
repository = "https://github.com/kamadorueda/alejandra"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
lto = true
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
|
|
|
@ -3,10 +3,18 @@ pub fn parse(args: Vec<String>) -> clap::ArgMatches {
|
||||||
.about("The Uncompromising Nix Code Formatter.")
|
.about("The Uncompromising Nix Code Formatter.")
|
||||||
.version(alejandra_engine::version::VERSION)
|
.version(alejandra_engine::version::VERSION)
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::new("paths")
|
clap::Arg::new("include")
|
||||||
.help("Files or directories, or none to format stdin.")
|
.help("Files or directories, or none to format stdin.")
|
||||||
.multiple_values(true),
|
.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)
|
.term_width(80)
|
||||||
.after_help(indoc::indoc!(
|
.after_help(indoc::indoc!(
|
||||||
// Let's just use the same sorting as on GitHub
|
// Let's just use the same sorting as on GitHub
|
||||||
|
@ -240,12 +248,12 @@ pub fn tui(
|
||||||
.bg(tui::style::Color::Black)
|
.bg(tui::style::Color::Black)
|
||||||
.add_modifier(tui::style::Modifier::ITALIC),
|
.add_modifier(tui::style::Modifier::ITALIC),
|
||||||
)
|
)
|
||||||
.percent(
|
.percent(if paths_to_format == 0 {
|
||||||
(100 * (paths_changed
|
100
|
||||||
+ paths_unchanged
|
} else {
|
||||||
+ paths_with_errors)
|
100 * (paths_changed + paths_unchanged + paths_with_errors)
|
||||||
/ paths_to_format) as u16,
|
/ paths_to_format
|
||||||
)
|
} as u16)
|
||||||
.style(
|
.style(
|
||||||
tui::style::Style::default()
|
tui::style::Style::default()
|
||||||
.bg(tui::style::Color::Black)
|
.bg(tui::style::Color::Black)
|
||||||
|
|
|
@ -1,11 +1,17 @@
|
||||||
pub fn nix_files(paths: Vec<&str>) -> Vec<String> {
|
pub fn nix_files(include: Vec<&str>, exclude: Vec<&str>) -> Vec<String> {
|
||||||
|
let include: std::collections::HashSet<String> =
|
||||||
|
include.iter().flat_map(nix_files_in_path).collect();
|
||||||
|
let exclude: std::collections::HashSet<String> =
|
||||||
|
exclude.iter().flat_map(nix_files_in_path).collect();
|
||||||
|
|
||||||
let mut paths: Vec<String> =
|
let mut paths: Vec<String> =
|
||||||
paths.iter().flat_map(nix_files_in_path).collect();
|
include.difference(&exclude).map(|path| path.clone()).collect();
|
||||||
|
|
||||||
paths.sort();
|
paths.sort();
|
||||||
paths
|
paths
|
||||||
}
|
}
|
||||||
|
|
||||||
fn nix_files_in_path(path: &&str) -> Vec<String> {
|
fn nix_files_in_path(path: &&str) -> std::collections::HashSet<String> {
|
||||||
walkdir::WalkDir::new(path)
|
walkdir::WalkDir::new(path)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_entry(is_nix_file_or_dir)
|
.filter_entry(is_nix_file_or_dir)
|
||||||
|
|
|
@ -3,10 +3,16 @@ fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
let config = alejandra_engine::config::Config::default();
|
let config = alejandra_engine::config::Config::default();
|
||||||
|
|
||||||
match matches.values_of("paths") {
|
match matches.values_of("include") {
|
||||||
Some(paths) => {
|
Some(include) => {
|
||||||
|
let include = include.collect();
|
||||||
|
let exclude = match matches.values_of("exclude") {
|
||||||
|
Some(exclude) => exclude.collect(),
|
||||||
|
None => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
let paths: Vec<String> =
|
let paths: Vec<String> =
|
||||||
alejandra_cli::find::nix_files(paths.collect());
|
alejandra_cli::find::nix_files(include, exclude);
|
||||||
|
|
||||||
if atty::is(atty::Stream::Stderr)
|
if atty::is(atty::Stream::Stderr)
|
||||||
&& atty::is(atty::Stream::Stdin)
|
&& atty::is(atty::Stream::Stdin)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue