diff --git a/docs/reference/rew-x.md b/docs/reference/rew-x.md index b34a6e9..029536d 100644 --- a/docs/reference/rew-x.md +++ b/docs/reference/rew-x.md @@ -308,7 +308,7 @@ rew x -s bash '{# for((i=0;i<3;i++)); do echo $i; done}. {}' The `:` marker is a hint that an expression does not consume stdin. Without it, the overall execution might get stuck forever due to blocked IO calls. -Only external commands need `:` to be explicitely specified. For built-in commands, `:` is detected automatically. +Only external commands need `:` to be explicitly specified. For built-in commands, `:` is detected automatically. ```sh rew x '{seq 1..3} {: !seq 1 3} {:# echo 1; echo 2; echo 3}' diff --git a/docs/reference/rew.md b/docs/reference/rew.md index 1f63677..d0f9dff 100644 --- a/docs/reference/rew.md +++ b/docs/reference/rew.md @@ -119,9 +119,9 @@ Can be also set using `REW_BUF_MODE` environment variable. Size of a buffer used for IO operations. -Smaller values will reduce memory consumption but could negatively affect througput. +Smaller values will reduce memory consumption but could negatively affect throughput. -Larger values will increase memory consumption but may improve troughput in some cases. +Larger values will increase memory consumption but may improve throughput in some cases. Certain commands (which can only operate with whole lines) won't be able to fetch a line bigger than this limit and will abort their execution instead. diff --git a/snapshots/error.svg b/snapshots/error.svg index 427ab03..076bbf2 100644 --- a/snapshots/error.svg +++ b/snapshots/error.svg @@ -68,7 +68,7 @@
$ rew x "{cat --unknown}"
rew cat (spawned by 'rew x'): invalid usage: unexpected argument found
-rew x: error: child proces execution failed
+rew x: error: child process execution failed
 rew x: └─> expression: {cat --unknown}
 rew x: └─> environment: REW_BUF_MODE="full" REW_BUF_SIZE="32768" REW_NULL="false
" _REW_SPAWNED_BY="rew x"
rew x: └─> command: "rew" "cat" "--unknown" diff --git a/snapshots/examples.svg b/snapshots/examples.svg index e883689..ffefe8c 100644 --- a/snapshots/examples.svg +++ b/snapshots/examples.svg @@ -161,7 +161,7 @@ A specific shell for {# ...} can be set using the : marker is a hint that an expression does not consume stdin. Without it, the overall execution might get stuck forever due to blocked IO calls. -Only external commands need : to be explicitely specified. For built-in +Only external commands need : to be explicitly specified. For built-in commands, : is detected automatically. ╭─────────────────────────────────────────────────────────────╮ diff --git a/snapshots/help.svg b/snapshots/help.svg index d683624..6cb4723 100644 --- a/snapshots/help.svg +++ b/snapshots/help.svg @@ -107,9 +107,9 @@ --buf-size <BYTES> Size of a buffer used for IO operations. - Smaller values will reduce memory consumption but could negatively aff
ect througput. + Smaller values will reduce memory consumption but could negatively aff
ect throughput. - Larger values will increase memory consumption but may improve troughp
ut in some cases. + Larger values will increase memory consumption but may improve through
put in some cases. Certain commands (which can only operate with whole lines) won't be ab
le to fetch a line bigger than this limit and will abort their execution instead. diff --git a/src/app.rs b/src/app.rs index 611e96c..87adf04 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,6 @@ use crate::colors::BOLD; use crate::colors::RESET; -use crate::command; +use crate::commands::METAS; use crate::env; use clap::command; use clap::crate_description; @@ -11,14 +11,14 @@ use clap::Command; const REFERENCE_URL: &str = "https://jpikl.github.io/rew/reference"; -pub fn build(metas: &[&'static command::Meta]) -> Command { +pub fn build() -> Command { let mut app = command!() .version(get_version()) .about(crate_description!().replace(". ", ".\n")) .after_help(get_after_help(None)) .subcommand_required(true); - for meta in metas { + for meta in METAS { let command = meta.build().after_help(get_after_help(Some(meta.name))); app = app.subcommand(command); } diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d5a4251..7e00821 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -15,7 +15,7 @@ mod trim; mod upper; mod x; -pub const COMMANDS: &[&Meta] = &[ +pub const METAS: &[&Meta] = &[ &ascii::META, &cat::META, &first::META, @@ -33,5 +33,5 @@ pub const COMMANDS: &[&Meta] = &[ ]; pub fn get_meta(name: &str) -> Option<&'static Meta> { - COMMANDS.iter().find(|meta| meta.name == name).copied() + METAS.iter().find(|meta| meta.name == name).copied() } diff --git a/src/commands/x.rs b/src/commands/x.rs index 5b20926..a64d9b6 100644 --- a/src/commands/x.rs +++ b/src/commands/x.rs @@ -94,7 +94,7 @@ const EXAMPLES: &[Example] = command_examples! [ }, "The `:` marker is a hint that an expression does not consume stdin. \ Without it, the overall execution might get stuck forever due to blocked IO calls.\n\n\ - Only external commands need `:` to be explicitely specified. \ + Only external commands need `:` to be explicitly specified. \ For built-in commands, `:` is detected automatically.": { args: &["{seq 1..3} {: !seq 1 3} {:# echo 1; echo 2; echo 3}"], input: &[], @@ -240,7 +240,7 @@ fn eval_pattern(context: &Context, pattern: &Pattern, shell: &Shell) -> Result<( } } - // Helper thead forwards main process stdin to every child process. + // Helper thread forwards main process stdin to every child process. let thread_context = context.clone(); let thread = thread::spawn(move || forward_input(&thread_context, consumers)); @@ -249,8 +249,8 @@ fn eval_pattern(context: &Context, pattern: &Pattern, shell: &Shell) -> Result<( wait_children(children)?; if thread.is_finished() { - // Join the thread only if it actually endeded. - // Otherwise, this would be stucked forewer! + // Join the thread only if it actually ended. + // Otherwise, this would be stuck forever! thread.join().map_err(resume_unwind)? } else { // The helper thread is blocked on read from stdin. @@ -283,7 +283,7 @@ fn build_pipeline(env: &Env, shell: &Shell, expr: &Expression) -> Result Result>>) -> Result<()> { if stdins.iter().all(Option::is_none) { - return Ok(()); // None of the child proceses use stdin. + return Ok(()); // None of the child processes use stdin. } let mut reader = context.byte_chunk_reader(); @@ -362,7 +362,7 @@ fn wait_children(mut children: Vec>) -> Result<()> { } // Give the remaining child processes some extra time to finish. - // Needed especialy in case program exists with error on Windows. + // Needed especially in case program exists with error on Windows. thread::sleep(Duration::from_millis(100)); // Just kill the ones which did not terminate on their own. diff --git a/src/env.rs b/src/env.rs index 77899c2..9a31229 100644 --- a/src/env.rs +++ b/src/env.rs @@ -20,7 +20,7 @@ pub const ENV_BUF_SIZE: &str = "REW_BUF_SIZE"; // Internal env variables: // // When `rew` is spawned as a child of some parent `rew` process, -// it recieves the parent's name through this environment variable. +// it receives the parent's name through this environment variable. pub const ENV_SPAWNED_BY: &str = "_REW_SPAWNED_BY"; #[derive(Clone, Copy, ValueEnum, Display, Debug, IsVariant, PartialEq, Eq)] @@ -64,9 +64,9 @@ pub struct Args { /// Size of a buffer used for IO operations. /// - /// Smaller values will reduce memory consumption but could negatively affect througput. + /// Smaller values will reduce memory consumption but could negatively affect throughput. /// - /// Larger values will increase memory consumption but may improve troughput in some cases. + /// Larger values will increase memory consumption but may improve throughput in some cases. /// /// Certain commands (which can only operate with whole lines) won't be able to fetch /// a line bigger than this limit and will abort their execution instead. diff --git a/src/main.rs b/src/main.rs index 4b54350..0dc6eeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,12 +1,11 @@ use rew::app; use rew::commands::get_meta; -use rew::commands::COMMANDS; use rew::error::Reporter; use std::io; use std::process::ExitCode; fn main() -> ExitCode { - let app = app::build(COMMANDS); + let app = app::build(); let reporter = Reporter::new(&app); let matches = match app.try_get_matches() { diff --git a/src/pager.rs b/src/pager.rs index 29d3803..1e84200 100644 --- a/src/pager.rs +++ b/src/pager.rs @@ -50,7 +50,7 @@ impl Pager { stdin .context .apply_to_err(err) - .context("failed to write to child process stdin") + .context("failed to write to pager process stdin") }) }); diff --git a/src/process.rs b/src/process.rs index 9018425..174b407 100644 --- a/src/process.rs +++ b/src/process.rs @@ -36,46 +36,42 @@ pub enum Command { } impl Command { - pub fn internal(meta: &'static Meta) -> Self { - Self::Internal { - meta, - args: Vec::new(), - } - } - pub fn detect(name: &str, args: &[String], external: bool) -> Self { if external { - return Self::External { - name: name.to_string(), - args: args.to_vec(), - }; + return Self::external(name, args); } if name == crate_name!() { if let Some((name, args)) = args.split_first() { if let Some(meta) = get_meta(name) { - return Self::Internal { - meta, - args: args.to_vec(), - }; + return Self::internal(meta, args); } } - - return Self::UnknownInternal { - args: args.to_vec(), - }; + return Self::unknown_internal(args); } if let Some(meta) = get_meta(name) { - return Self::Internal { - meta, - args: args.to_vec(), - }; + return Self::internal(meta, args); } + Self::external(name, args) + } + + pub fn internal(meta: &'static Meta, args: impl Into>) -> Self { + Self::Internal { + meta, + args: args.into(), + } + } + + pub fn unknown_internal(args: impl Into>) -> Self { + Self::UnknownInternal { args: args.into() } + } + + pub fn external(name: impl Into, args: impl Into>) -> Self { Self::External { - name: name.to_string(), - args: args.to_vec(), + name: name.into(), + args: args.into(), } } @@ -93,14 +89,14 @@ impl Command { pub fn build(&self, env: &Env) -> Result { match self { Command::Internal { meta, args } => { - let mut command = internal_command()?; + let mut command = new_internal_command()?; command.arg(meta.name); command.args(args); command.envs(env.internal()); Ok(command) } Command::UnknownInternal { args } => { - let mut command = internal_command()?; + let mut command = new_internal_command()?; command.args(args); command.envs(env.internal()); Ok(command) @@ -115,7 +111,7 @@ impl Command { } } -fn internal_command() -> Result { +fn new_internal_command() -> Result { let program = current_exe().context("could not detect current executable")?; Ok(process::Command::new(program)) } diff --git a/src/spawn.rs b/src/spawn.rs index f46f385..f71aaf2 100644 --- a/src/spawn.rs +++ b/src/spawn.rs @@ -110,7 +110,7 @@ impl Spawned { fn wait_context(&self, error: impl Into) -> Error { self.context .apply_to_err(error) - .context("child proces execution failed") + .context("child process execution failed") } pub fn kill(&mut self) -> Result<()> { diff --git a/src/stdbuf.rs b/src/stdbuf.rs index bb48ccd..33eac6f 100644 --- a/src/stdbuf.rs +++ b/src/stdbuf.rs @@ -18,7 +18,7 @@ impl StdBuf { // This is probably the least invasive way how to force output line buffering on external commands (which use libc). // 1. Run `stdbuf [args] env` and extract relevant environment variables from its output. - // 2. Run the external command with those same enviroment variables (as `stdbuf` would do). + // 2. Run the external command with those same environment variables (as `stdbuf` would do). // // Alternatively we could: // a) Run external commands directly under `stdbuf`. This produces rather confusing error messages diff --git a/tests/examples.rs b/tests/examples.rs index 8805627..7692fc6 100644 --- a/tests/examples.rs +++ b/tests/examples.rs @@ -4,7 +4,7 @@ use std::env; #[test] fn examples() { - for meta in rew::commands::COMMANDS { + for meta in rew::commands::METAS { for example in meta.examples { // Such examples require coreutils with NUL separator support // which are not available on MacOS by default. diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 98c6e5d..8a6c63a 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -8,7 +8,6 @@ use command::Adapter; use docs::generate_reference; use docs::generate_summary; use rew::app; -use rew::commands::COMMANDS; use std::env; use std::fs::create_dir_all; use std::path::Path; @@ -39,7 +38,7 @@ fn main() -> anyhow::Result<()> { let cli = Cli::parse(); - let mut app = app::build(COMMANDS); + let mut app = app::build(); app.build(); match cli.task {