Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Note shebang line splitting inconsistency in readme #757

Merged
merged 3 commits into from
Feb 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/compilation_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
23 changes: 10 additions & 13 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -756,8 +757,6 @@ impl Config {
println!();
}
}

Ok(())
}

fn run(
Expand Down Expand Up @@ -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 {
Expand All @@ -810,18 +809,16 @@ 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!(" ");
}
print!("{}", assignment.name)
}
println!();
Ok(())
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
10 changes: 5 additions & 5 deletions src/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ impl Function {
}

fn arch(_context: &FunctionContext) -> Result<String, String> {
Ok(target::arch().to_string())
Ok(target::arch().to_owned())
}

fn os(_context: &FunctionContext) -> Result<String, String> {
Ok(target::os().to_string())
Ok(target::os().to_owned())
}

fn os_family(_context: &FunctionContext) -> Result<String, String> {
Ok(target::os_family().to_string())
Ok(target::os_family().to_owned())
}

fn invocation_directory(context: &FunctionContext) -> Result<String, String> {
Platform::to_shell_path(
Platform::convert_native_path(
&context.search.working_directory,
context.invocation_directory,
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/interrupt_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(crate) fn output(mut command: Command) -> Result<String, OutputError> {
} else {
utf8
}
.to_string(),
.to_owned(),
),
}
},
Expand Down
2 changes: 1 addition & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})),
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ impl PlatformInterface for Platform {
exit_status.signal()
}

fn to_shell_path(_working_directory: &Path, path: &Path) -> Result<String, String> {
fn convert_native_path(_working_directory: &Path, path: &Path) -> Result<String, String> {
path
.to_str()
.map(str::to_string)
Expand Down Expand Up @@ -91,7 +91,7 @@ impl PlatformInterface for Platform {
None
}

fn to_shell_path(working_directory: &Path, path: &Path) -> Result<String, String> {
fn convert_native_path(working_directory: &Path, path: &Path) -> Result<String, String> {
// Translate path from windows style to unix style
let mut cygpath = Command::new("cygpath");
cygpath.current_dir(working_directory);
Expand Down
2 changes: 1 addition & 1 deletion src/platform_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ pub(crate) trait PlatformInterface {
fn signal_from_exit_status(exit_status: process::ExitStatus) -> Option<i32>;

/// Translate a path from a "native" path to a path the interpreter expects
fn to_shell_path(working_directory: &Path, path: &Path) -> Result<String, String>;
fn convert_native_path(working_directory: &Path, path: &Path) -> Result<String, String>;
}
4 changes: 2 additions & 2 deletions src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
});
Expand Down
6 changes: 3 additions & 3 deletions tests/invocation_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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");
Expand Down Expand Up @@ -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();
Expand Down