mirror of
https://github.com/crate-ci/typos.git
synced 2025-02-15 09:33:00 -05:00
feat(cli): Add a --sort flag
This commit is contained in:
parent
ad80305210
commit
eb99975267
7 changed files with 17 additions and 4 deletions
|
@ -40,6 +40,10 @@ pub(crate) struct Args {
|
||||||
#[arg(short = 'j', long = "threads", default_value = "0")]
|
#[arg(short = 'j', long = "threads", default_value = "0")]
|
||||||
pub(crate) threads: usize,
|
pub(crate) threads: usize,
|
||||||
|
|
||||||
|
/// Sort results
|
||||||
|
#[arg(long)]
|
||||||
|
pub(crate) sort: bool,
|
||||||
|
|
||||||
/// Respect excluded files even for paths passed explicitly.
|
/// Respect excluded files even for paths passed explicitly.
|
||||||
#[arg(long, help_heading = None)]
|
#[arg(long, help_heading = None)]
|
||||||
pub(crate) force_exclude: bool,
|
pub(crate) force_exclude: bool,
|
||||||
|
|
|
@ -221,7 +221,11 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
|
||||||
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
|
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
|
||||||
let walk_policy = engine.walk(&cwd);
|
let walk_policy = engine.walk(&cwd);
|
||||||
|
|
||||||
let threads = if path.is_file() { 1 } else { args.threads };
|
let threads = if path.is_file() || args.sort {
|
||||||
|
1
|
||||||
|
} else {
|
||||||
|
args.threads
|
||||||
|
};
|
||||||
let single_threaded = threads == 1;
|
let single_threaded = threads == 1;
|
||||||
|
|
||||||
let mut walk = ignore::WalkBuilder::new(path);
|
let mut walk = ignore::WalkBuilder::new(path);
|
||||||
|
@ -233,6 +237,9 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
|
||||||
.git_ignore(walk_policy.ignore_vcs())
|
.git_ignore(walk_policy.ignore_vcs())
|
||||||
.git_exclude(walk_policy.ignore_vcs())
|
.git_exclude(walk_policy.ignore_vcs())
|
||||||
.parents(walk_policy.ignore_parent());
|
.parents(walk_policy.ignore_parent());
|
||||||
|
if args.sort {
|
||||||
|
walk.sort_by_file_name(|a, b| a.cmp(b));
|
||||||
|
}
|
||||||
if !walk_policy.extend_exclude.is_empty() {
|
if !walk_policy.extend_exclude.is_empty() {
|
||||||
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
|
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
|
||||||
for pattern in walk_policy.extend_exclude.iter() {
|
for pattern in walk_policy.extend_exclude.iter() {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
bin.name = "typos"
|
bin.name = "typos"
|
||||||
|
args = "--sort"
|
||||||
status.code = 2
|
status.code = 2
|
||||||
stdin = ""
|
stdin = ""
|
||||||
stdout = """
|
stdout = """
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
bin.name = "typos"
|
bin.name = "typos"
|
||||||
args = "-j1"
|
args = "--sort"
|
||||||
stdin = ""
|
stdin = ""
|
||||||
stdout = """
|
stdout = """
|
||||||
error: `hello` should be `goodbye`
|
error: `hello` should be `goodbye`
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
bin.name = "typos"
|
bin.name = "typos"
|
||||||
args = "--file-list -"
|
args = "--sort --file-list -"
|
||||||
stdin = """
|
stdin = """
|
||||||
b.fail
|
b.fail
|
||||||
d.fail
|
d.fail
|
||||||
|
|
|
@ -11,6 +11,7 @@ Arguments:
|
||||||
Options:
|
Options:
|
||||||
--file-list <FILE_LIST> Read the list of newline separated paths from file or stdin (if `-`)
|
--file-list <FILE_LIST> Read the list of newline separated paths from file or stdin (if `-`)
|
||||||
-j, --threads <THREADS> The approximate number of threads to use [default: 0]
|
-j, --threads <THREADS> The approximate number of threads to use [default: 0]
|
||||||
|
--sort Sort results
|
||||||
--force-exclude Respect excluded files even for paths passed explicitly
|
--force-exclude Respect excluded files even for paths passed explicitly
|
||||||
-h, --help Print help
|
-h, --help Print help
|
||||||
-V, --version Print version
|
-V, --version Print version
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
bin.name = "typos"
|
bin.name = "typos"
|
||||||
stdin = ""
|
stdin = "--sort"
|
||||||
stdout = """
|
stdout = """
|
||||||
error: `hello` should be `goodbye`
|
error: `hello` should be `goodbye`
|
||||||
--> ./file.ignore:1:1
|
--> ./file.ignore:1:1
|
||||||
|
|
Loading…
Add table
Reference in a new issue