mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-30 12:07:46 +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"
|
||||
version = "0.3.1"
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
||||
[workspace]
|
||||
|
|
|
@ -3,10 +3,18 @@ pub fn parse(args: Vec<String>) -> 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)
|
||||
|
|
|
@ -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> =
|
||||
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<String> {
|
||||
fn nix_files_in_path(path: &&str) -> std::collections::HashSet<String> {
|
||||
walkdir::WalkDir::new(path)
|
||||
.into_iter()
|
||||
.filter_entry(is_nix_file_or_dir)
|
||||
|
|
|
@ -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<String> =
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue