From 7ae890ce6137a3e15df5327265a3042e952fe215 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 15 Feb 2021 01:18:31 -0800 Subject: [PATCH] Note shebang line splitting inconsistency in readme (#757) --- README.adoc | 9 +++++++++ src/compilation_error.rs | 8 ++++---- src/config.rs | 23 ++++++++++------------- src/evaluator.rs | 2 +- src/function.rs | 10 +++++----- src/interrupt_handler.rs | 2 +- src/lib.rs | 1 + src/output.rs | 2 +- src/parser.rs | 2 +- src/platform.rs | 4 ++-- src/platform_interface.rs | 2 +- src/recipe.rs | 4 ++-- tests/invocation_directory.rs | 6 +++--- 13 files changed, 41 insertions(+), 34 deletions(-) diff --git a/README.adoc b/README.adoc index 8fca36970c..b6326c4e5b 100644 --- a/README.adoc +++ b/README.adoc @@ -1224,6 +1224,15 @@ When a script with a shebang is executed, the system supplies the path to the sc With the above shebang, `just` will change its working directory to the location of the script. If you'd rather leave the working directory unchanged, use `#!/usr/bin/env just --working-directory . --justfile`. +Note: Shebang line splitting is not consistent across operating systems. The previous examples have only been tested on macOS. On Linux, you may need to pass the `-S` flag to `env`: + +``` +#!/usr/bin/env -S just --justfile + +default: + echo foo +``` + == Miscellanea === Companion Tools diff --git a/src/compilation_error.rs b/src/compilation_error.rs index 1754543bec..7947a4e5ec 100644 --- a/src/compilation_error.rs +++ b/src/compilation_error.rs @@ -54,10 +54,10 @@ impl Display for CompilationError<'_> { InvalidEscapeSequence { character } => { let representation = match character { - '`' => r"\`".to_string(), - '\\' => r"\".to_string(), - '\'' => r"'".to_string(), - '"' => r#"""#.to_string(), + '`' => r"\`".to_owned(), + '\\' => r"\".to_owned(), + '\'' => r"'".to_owned(), + '"' => r#"""#.to_owned(), _ => character.escape_default().collect(), }; writeln!(f, "`\\{}` is not a valid escape sequence", representation)?; diff --git a/src/config.rs b/src/config.rs index 3842298443..520c9f7ca4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -512,19 +512,21 @@ impl Config { match &self.subcommand { Choose { overrides, chooser } => - self.choose(justfile, &search, overrides, chooser.as_deref()), + self.choose(justfile, &search, overrides, chooser.as_deref())?, Dump => Self::dump(justfile), - Evaluate { overrides } => self.run(justfile, &search, overrides, &[]), + Evaluate { overrides } => self.run(justfile, &search, overrides, &[])?, List => self.list(justfile), Run { arguments, overrides, - } => self.run(justfile, &search, overrides, arguments), - Show { ref name } => Self::show(&name, justfile), + } => self.run(justfile, &search, overrides, arguments)?, + Show { ref name } => Self::show(&name, justfile)?, Summary => self.summary(justfile), Variables => Self::variables(justfile), Completions { .. } | Edit | Init => unreachable!(), } + + Ok(()) } fn choose( @@ -620,9 +622,8 @@ impl Config { self.run(justfile, search, overrides, &recipes) } - fn dump(justfile: Justfile) -> Result<(), i32> { + fn dump(justfile: Justfile) { println!("{}", justfile); - Ok(()) } pub(crate) fn edit(search: &Search) -> Result<(), i32> { @@ -674,7 +675,7 @@ impl Config { } } - fn list(&self, justfile: Justfile) -> Result<(), i32> { + fn list(&self, justfile: Justfile) { // Construct a target to alias map. let mut recipe_aliases: BTreeMap<&str, Vec<&str>> = BTreeMap::new(); for alias in justfile.aliases.values() { @@ -756,8 +757,6 @@ impl Config { println!(); } } - - Ok(()) } fn run( @@ -798,7 +797,7 @@ impl Config { } } - fn summary(&self, justfile: Justfile) -> Result<(), i32> { + fn summary(&self, justfile: Justfile) { if justfile.count() == 0 { eprintln!("Justfile contains no recipes."); } else { @@ -810,10 +809,9 @@ impl Config { .join(" "); println!("{}", summary); } - Ok(()) } - fn variables(justfile: Justfile) -> Result<(), i32> { + fn variables(justfile: Justfile) { for (i, (_, assignment)) in justfile.assignments.iter().enumerate() { if i > 0 { print!(" "); @@ -821,7 +819,6 @@ impl Config { print!("{}", assignment.name) } println!(); - Ok(()) } } diff --git a/src/evaluator.rs b/src/evaluator.rs index b56a6ad498..70da605770 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -212,7 +212,7 @@ impl<'src, 'run> Evaluator<'src, 'run> { String::new() } else { return Err(RuntimeError::Internal { - message: "missing parameter without default".to_string(), + message: "missing parameter without default".to_owned(), }); } } else if parameter.kind.is_variadic() { diff --git a/src/function.rs b/src/function.rs index 4505198710..dffb3a51e6 100644 --- a/src/function.rs +++ b/src/function.rs @@ -34,19 +34,19 @@ impl Function { } fn arch(_context: &FunctionContext) -> Result { - Ok(target::arch().to_string()) + Ok(target::arch().to_owned()) } fn os(_context: &FunctionContext) -> Result { - Ok(target::os().to_string()) + Ok(target::os().to_owned()) } fn os_family(_context: &FunctionContext) -> Result { - Ok(target::os_family().to_string()) + Ok(target::os_family().to_owned()) } fn invocation_directory(context: &FunctionContext) -> Result { - Platform::to_shell_path( + Platform::convert_native_path( &context.search.working_directory, context.invocation_directory, ) @@ -115,7 +115,7 @@ fn env_var_or_default( } match env::var(key) { - Err(NotPresent) => Ok(default.to_string()), + Err(NotPresent) => Ok(default.to_owned()), Err(NotUnicode(os_string)) => Err(format!( "environment variable `{}` not unicode: {:?}", key, os_string diff --git a/src/interrupt_handler.rs b/src/interrupt_handler.rs index fe26eb99fa..65e40a8333 100644 --- a/src/interrupt_handler.rs +++ b/src/interrupt_handler.rs @@ -54,7 +54,7 @@ impl InterruptHandler { pub(crate) fn unblock(&mut self) { if self.blocks == 0 { eprintln!("{}", RuntimeError::Internal { - message: "attempted to unblock interrupt handler, but handler was not blocked".to_string(), + message: "attempted to unblock interrupt handler, but handler was not blocked".to_owned(), }); std::process::exit(EXIT_FAILURE); } diff --git a/src/lib.rs b/src/lib.rs index 171066c3b6..fe9a0a44d2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,7 @@ clippy::string_add, clippy::struct_excessive_bools, clippy::too_many_lines, + clippy::unnecessary_wraps, clippy::unreachable, clippy::unwrap_in_result, clippy::unwrap_used, diff --git a/src/output.rs b/src/output.rs index 486d8ce51c..680284ec6c 100644 --- a/src/output.rs +++ b/src/output.rs @@ -25,7 +25,7 @@ pub(crate) fn output(mut command: Command) -> Result { } else { utf8 } - .to_string(), + .to_owned(), ), } }, diff --git a/src/parser.rs b/src/parser.rs index 69dcbfc81c..d66eb131e9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -527,7 +527,7 @@ impl<'tokens, 'src> Parser<'tokens, 'src> { }) }, _ => Err(token.error(CompilationErrorKind::Internal { - message: "`Parser::parse_string_literal` called on non-string token".to_string(), + message: "`Parser::parse_string_literal` called on non-string token".to_owned(), })), } } diff --git a/src/platform.rs b/src/platform.rs index ac00b85019..cbaf67ee52 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -37,7 +37,7 @@ impl PlatformInterface for Platform { exit_status.signal() } - fn to_shell_path(_working_directory: &Path, path: &Path) -> Result { + fn convert_native_path(_working_directory: &Path, path: &Path) -> Result { path .to_str() .map(str::to_string) @@ -91,7 +91,7 @@ impl PlatformInterface for Platform { None } - fn to_shell_path(working_directory: &Path, path: &Path) -> Result { + fn convert_native_path(working_directory: &Path, path: &Path) -> Result { // Translate path from windows style to unix style let mut cygpath = Command::new("cygpath"); cygpath.current_dir(working_directory); diff --git a/src/platform_interface.rs b/src/platform_interface.rs index 5b958ad792..eca029dcd5 100644 --- a/src/platform_interface.rs +++ b/src/platform_interface.rs @@ -18,5 +18,5 @@ pub(crate) trait PlatformInterface { fn signal_from_exit_status(exit_status: process::ExitStatus) -> Option; /// Translate a path from a "native" path to a path the interpreter expects - fn to_shell_path(working_directory: &Path, path: &Path) -> Result; + fn convert_native_path(working_directory: &Path, path: &Path) -> Result; } diff --git a/src/recipe.rs b/src/recipe.rs index e2d2601b42..48767cb275 100644 --- a/src/recipe.rs +++ b/src/recipe.rs @@ -154,7 +154,7 @@ impl<'src, D> Recipe<'src, D> { let shebang_line = evaluated_lines .first() .ok_or_else(|| RuntimeError::Internal { - message: "evaluated_lines was empty".to_string(), + message: "evaluated_lines was empty".to_owned(), })?; let Shebang { @@ -195,7 +195,7 @@ impl<'src, D> Recipe<'src, D> { Err(io_error) => { return Err(RuntimeError::Shebang { recipe: self.name(), - command: interpreter.to_string(), + command: interpreter.to_owned(), argument: argument.map(String::from), io_error, }); diff --git a/tests/invocation_directory.rs b/tests/invocation_directory.rs index a7bfc07ea2..f819513c2f 100644 --- a/tests/invocation_directory.rs +++ b/tests/invocation_directory.rs @@ -4,7 +4,7 @@ use executable_path::executable_path; use test_utilities::tempdir; #[cfg(unix)] -fn to_shell_path(path: &Path) -> String { +fn convert_native_path(path: &Path) -> String { fs::canonicalize(path) .expect("canonicalize failed") .to_str() @@ -13,7 +13,7 @@ fn to_shell_path(path: &Path) -> String { } #[cfg(windows)] -fn to_shell_path(path: &Path) -> String { +fn convert_native_path(path: &Path) -> String { // Translate path from windows style to unix style let mut cygpath = process::Command::new("cygpath"); cygpath.arg("--unix"); @@ -60,7 +60,7 @@ fn test_invocation_directory() { let mut failure = false; let expected_status = 0; - let expected_stdout = to_shell_path(&subdir) + "\n"; + let expected_stdout = convert_native_path(&subdir) + "\n"; let expected_stderr = ""; let status = output.status.code().unwrap();