oxc/crates/oxc_cli/src/command/format.rs
Andi Pabst 4c5abb590e
feat(cli): wildcard expansion in paths for windows (#2767)
Unlike on other OS, on Windows there is no wildcard expansion/globbing
by the shell. Instead the application has to handle this. Therefore I
used the `glob` package to handle wildcards on Windows.

I also had to make the parent directory check more strict due to the
glob package resolving `..` in the middle of the path as well.

This closes #2695.
2024-03-22 00:21:30 +08:00

36 lines
938 B
Rust

use std::path::PathBuf;
use bpaf::Bpaf;
use super::{
expand_glob,
ignore::{ignore_options, IgnoreOptions},
misc_options, validate_paths, CliCommand, MiscOptions, PATHS_ERROR_MESSAGE, VERSION,
};
/// Formatter for the JavaScript Oxidation Compiler
#[derive(Debug, Clone, Bpaf)]
#[bpaf(options, version(VERSION))]
pub struct FormatCommand {
#[bpaf(external(format_options))]
pub format_options: FormatOptions,
}
impl FormatCommand {
pub fn handle_threads(&self) {
CliCommand::set_rayon_threads(self.format_options.misc_options.threads);
}
}
#[derive(Debug, Clone, Bpaf)]
pub struct FormatOptions {
#[bpaf(external)]
pub misc_options: MiscOptions,
#[bpaf(external)]
pub ignore_options: IgnoreOptions,
/// Single file, single path or list of paths
#[bpaf(positional("PATH"), many, guard(validate_paths, PATHS_ERROR_MESSAGE), map(expand_glob))]
pub paths: Vec<PathBuf>,
}