mirror of
https://github.com/RGBCube/alejandra
synced 2025-07-31 12:37:45 +00:00
feat: respect - for stdin
This commit is contained in:
parent
8f724a92c4
commit
36f44e93e3
2 changed files with 10 additions and 7 deletions
|
@ -17,20 +17,20 @@ const AFTER_HELP: &str = indoc::indoc! {"
|
||||||
"
|
"
|
||||||
};
|
};
|
||||||
|
|
||||||
/// The Uncompromising Nix Code Formatter
|
/// The Uncompromising Nix Code Formatter.
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(version, after_help = AFTER_HELP, term_width = 80)]
|
#[clap(version, after_help = AFTER_HELP, term_width = 80)]
|
||||||
struct Args {
|
struct Args {
|
||||||
/// Files or directories, or none to format stdin
|
/// Files or directories, or a single "-" (or leave empty) to format stdin.
|
||||||
#[clap(multiple_values = true)]
|
#[clap(multiple_values = true)]
|
||||||
include: Vec<String>,
|
include: Vec<String>,
|
||||||
|
|
||||||
/// Files or directories to exclude from formatting
|
/// Files or directories to exclude from formatting.
|
||||||
#[clap(long, short, multiple_occurrences = true)]
|
#[clap(long, short, multiple_occurrences = true)]
|
||||||
exclude: Vec<String>,
|
exclude: Vec<String>,
|
||||||
|
|
||||||
/// Check if the input is already formatted and disable writing in-place
|
/// Check if the input is already formatted and disable writing in-place
|
||||||
/// the modified content
|
/// the modified content.
|
||||||
#[clap(long, short)]
|
#[clap(long, short)]
|
||||||
check: bool,
|
check: bool,
|
||||||
|
|
||||||
|
@ -334,8 +334,11 @@ pub fn main() -> std::io::Result<()> {
|
||||||
.build_global()
|
.build_global()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let formatted_paths = match &args.include[..] {
|
let include: Vec<&str> =
|
||||||
&[] => {
|
args.include.iter().map(String::as_str).collect::<Vec<&str>>();
|
||||||
|
|
||||||
|
let formatted_paths = match &include[..] {
|
||||||
|
&[] | &["-"] => {
|
||||||
vec![crate::cli::stdin(args.quiet)]
|
vec![crate::cli::stdin(args.quiet)]
|
||||||
}
|
}
|
||||||
include => {
|
include => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
|
||||||
pub(crate) fn nix_files(include: &[String], exclude: &[String]) -> Vec<String> {
|
pub(crate) fn nix_files(include: &[&str], exclude: &[String]) -> Vec<String> {
|
||||||
let include: HashSet<_> =
|
let include: HashSet<_> =
|
||||||
include.iter().flat_map(|s| nix_files_in_path(s)).collect();
|
include.iter().flat_map(|s| nix_files_in_path(s)).collect();
|
||||||
let exclude: HashSet<_> =
|
let exclude: HashSet<_> =
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue