Skip to content

Commit

Permalink
Merge pull request #588 from epage/update
Browse files Browse the repository at this point in the history
chore: Upgrade proc-exit
  • Loading branch information
epage authored Oct 4, 2022
2 parents 17a90d8 + 2b667ff commit ec8713a
Show file tree
Hide file tree
Showing 16 changed files with 72 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.60.0" # MSRV
msrv = "1.64.0" # MSRV
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ jobs:
- name: No-default features
run: cargo test --workspace --no-default-features
msrv:
name: "Check MSRV: 1.60.0"
name: "Check MSRV: 1.64.0"
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.60.0 # MSRV
toolchain: 1.64.0 # MSRV
profile: minimal
override: true
- uses: Swatinem/rust-cache@v1
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.60.0 # MSRV
toolchain: 1.64.0 # MSRV
profile: minimal
override: true
components: clippy
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ jobs:
strategy:
matrix:
rust:
- 1.60.0 # MSRV
- 1.64.0 # MSRV
- stable
continue-on-error: ${{ matrix.rust != '1.60.0' }} # MSRV
continue-on-error: ${{ matrix.rust != '1.64.0' }} # MSRV
runs-on: ubuntu-latest
steps:
- name: Checkout repository
Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand Down Expand Up @@ -73,7 +73,7 @@ bstr = "1.0"
once_cell = "1.15.0"
ahash = "0.8"
difflib = "0.4"
proc-exit = "1.0"
proc-exit = "2.0"
human-panic = "1.0.3"
content_inspector = "0.2.4"
unicode-segmentation = "1.10.0"
Expand Down
2 changes: 1 addition & 1 deletion crates/codespell-dict/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
license = "CC-BY-SA-3.0"
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
publish = false
include = [
"src/**/*",
Expand Down
2 changes: 1 addition & 1 deletion crates/dictgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling", "no_std"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand Down
4 changes: 2 additions & 2 deletions crates/dictgen/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ impl<V> DictTrie<V> {
match child.children {
DictTrieChild::Nested(n) => {
let byte = bytes[i];
let index = if (b'a'..b'z').contains(&byte) {
let index = if (b'a'..=b'z').contains(&byte) {
byte - b'a'
} else if (b'A'..b'Z').contains(&byte) {
} else if (b'A'..=b'Z').contains(&byte) {
byte - b'A'
} else {
return self.unicode.find(word);
Expand Down
2 changes: 1 addition & 1 deletion crates/misspell-dict/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
license = "MIT OR Apache-2.0"
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
publish = false
include = [
"src/**/*",
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-dict/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../../README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand Down
2 changes: 1 addition & 1 deletion crates/typos-vars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../../README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand Down
2 changes: 1 addition & 1 deletion crates/typos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../../README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand Down
2 changes: 1 addition & 1 deletion crates/varcon-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repository = "https://github.com/crate-ci/typos"
readme = "../../README.md"
categories = ["text-processing"]
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand Down
2 changes: 1 addition & 1 deletion crates/varcon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../../README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
include = [
"src/**/*",
"Cargo.toml",
Expand Down
2 changes: 1 addition & 1 deletion crates/wikipedia-dict/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "README.md"
categories = ["development-tools", "text-processing"]
keywords = ["development", "spelling"]
edition = "2021"
rust-version = "1.60.0" # MSRV
rust-version = "1.64.0" # MSRV
publish = false
include = [
"src/**/*",
Expand Down
80 changes: 51 additions & 29 deletions src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use clap::Parser;
mod args;
mod report;

use proc_exit::WithCodeResultExt;
use proc_exit::prelude::*;

fn main() {
human_panic::setup_panic!();
Expand All @@ -19,7 +19,7 @@ fn run() -> proc_exit::ExitResult {
Ok(args) => args,
Err(e) if e.use_stderr() => {
let _ = e.print();
return proc_exit::Code::USAGE_ERR.ok();
return proc_exit::sysexits::USAGE_ERR.ok();
}
Err(e) => {
let _ = e.print();
Expand Down Expand Up @@ -52,87 +52,99 @@ fn run() -> proc_exit::ExitResult {
}

fn run_dump_config(args: &args::Args, output_path: &std::path::Path) -> proc_exit::ExitResult {
let global_cwd = std::env::current_dir()?;
let global_cwd = std::env::current_dir().to_sysexits()?;

let path = &args.path[0];
let cwd = if path == std::path::Path::new("-") {
global_cwd
} else if path.is_file() {
let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
let mut cwd = path
.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?;
cwd.pop();
cwd
} else {
path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
path.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?
};
let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
let cwd = cwd
.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?;

let storage = typos_cli::policy::ConfigStorage::new();
let mut engine = typos_cli::policy::ConfigEngine::new(&storage);
engine.set_isolated(args.isolated);

let mut overrides = typos_cli::config::Config::default();
if let Some(path) = args.custom_config.as_ref() {
let custom =
typos_cli::config::Config::from_file(path).with_code(proc_exit::Code::CONFIG_ERR)?;
let custom = typos_cli::config::Config::from_file(path)
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
overrides.update(&custom);
}
overrides.update(&args.config.to_config());
engine.set_overrides(overrides);

let config = engine
.load_config(&cwd)
.with_code(proc_exit::Code::CONFIG_ERR)?;
.with_code(proc_exit::sysexits::CONFIG_ERR)?;

let mut defaulted_config = typos_cli::config::Config::from_defaults();
defaulted_config.update(&config);
let output =
toml_edit::easy::to_string_pretty(&defaulted_config).with_code(proc_exit::Code::FAILURE)?;
if output_path == std::path::Path::new("-") {
std::io::stdout().write_all(output.as_bytes())?;
std::io::stdout()
.write_all(output.as_bytes())
.to_sysexits()?;
} else {
std::fs::write(output_path, &output)?;
std::fs::write(output_path, &output).to_sysexits()?;
}

Ok(())
}

fn run_type_list(args: &args::Args) -> proc_exit::ExitResult {
let global_cwd = std::env::current_dir()?;
let global_cwd = std::env::current_dir().to_sysexits()?;

let path = &args.path[0];
let cwd = if path == std::path::Path::new("-") {
global_cwd
} else if path.is_file() {
let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
let mut cwd = path
.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?;
cwd.pop();
cwd
} else {
path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
path.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?
};
let cwd = cwd.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
let cwd = cwd
.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?;

let storage = typos_cli::policy::ConfigStorage::new();
let mut engine = typos_cli::policy::ConfigEngine::new(&storage);
engine.set_isolated(args.isolated);

let mut overrides = typos_cli::config::Config::default();
if let Some(path) = args.custom_config.as_ref() {
let custom =
typos_cli::config::Config::from_file(path).with_code(proc_exit::Code::CONFIG_ERR)?;
let custom = typos_cli::config::Config::from_file(path)
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
overrides.update(&custom);
}
overrides.update(&args.config.to_config());
engine.set_overrides(overrides);

engine
.init_dir(&cwd)
.with_code(proc_exit::Code::CONFIG_ERR)?;
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
let definitions = engine.file_types(&cwd);

let stdout = std::io::stdout();
let mut handle = stdout.lock();
for (name, globs) in definitions {
writeln!(handle, "{}: {}", name, itertools::join(globs, ", "))?;
writeln!(handle, "{}: {}", name, itertools::join(globs, ", ")).to_sysexits()?;
}

Ok(())
Expand All @@ -143,16 +155,16 @@ fn run_checks(
stdout_palette: report::Palette,
stderr_palette: report::Palette,
) -> proc_exit::ExitResult {
let global_cwd = std::env::current_dir()?;
let global_cwd = std::env::current_dir().to_sysexits()?;

let storage = typos_cli::policy::ConfigStorage::new();
let mut engine = typos_cli::policy::ConfigEngine::new(&storage);
engine.set_isolated(args.isolated);

let mut overrides = typos_cli::config::Config::default();
if let Some(path) = args.custom_config.as_ref() {
let custom =
typos_cli::config::Config::from_file(path).with_code(proc_exit::Code::CONFIG_ERR)?;
let custom = typos_cli::config::Config::from_file(path)
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
overrides.update(&custom);
}
overrides.update(&args.config.to_config());
Expand All @@ -164,16 +176,19 @@ fn run_checks(
let cwd = if path == std::path::Path::new("-") {
global_cwd.clone()
} else if path.is_file() {
let mut cwd = path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?;
let mut cwd = path
.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?;
cwd.pop();
cwd
} else {
path.canonicalize().with_code(proc_exit::Code::USAGE_ERR)?
path.canonicalize()
.with_code(proc_exit::sysexits::USAGE_ERR)?
};

engine
.init_dir(&cwd)
.with_code(proc_exit::Code::CONFIG_ERR)?;
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
let walk_policy = engine.walk(&cwd);

let threads = if path.is_file() { 1 } else { args.threads };
Expand All @@ -193,9 +208,11 @@ fn run_checks(
for pattern in walk_policy.extend_exclude.iter() {
overrides
.add(&format!("!{}", pattern))
.with_code(proc_exit::Code::CONFIG_ERR)?;
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
}
let overrides = overrides.build().with_code(proc_exit::Code::CONFIG_ERR)?;
let overrides = overrides
.build()
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
walk.overrides(overrides);
}

Expand Down Expand Up @@ -234,7 +251,12 @@ fn run_checks(
}
.map_err(|e| {
e.io_error()
.map(|i| proc_exit::Code::from(i.kind()))
.map(|i| {
let kind = i.kind();
proc_exit::sysexits::io_to_sysexists(kind)
.or_else(|| proc_exit::bash::io_to_signal(kind))
.unwrap_or(proc_exit::sysexits::IO_ERR)
})
.unwrap_or_default()
.with_message(e)
})?;
Expand All @@ -253,7 +275,7 @@ fn run_checks(
// `Failure` from something else and get it mixed up with typos.
//
// Can't use DataErr or anything else an std::io::ErrorKind might map to.
proc_exit::Code::UNKNOWN.ok()
proc_exit::Code::new(2).ok()
} else {
proc_exit::Code::SUCCESS.ok()
}
Expand Down

0 comments on commit ec8713a

Please sign in to comment.