From d0b52788e9a09674dc90b290b01dd14098b85d83 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 8 Apr 2019 01:04:11 -0700 Subject: [PATCH 1/7] Allow outer shebangs so justfiles can be used as scripts --- README.adoc | 25 +++++++++++++++++++++++++ justfile | 4 ++++ src/compilation_error.rs | 4 ---- src/lexer.rs | 16 ++-------------- tests/integration.rs | 22 ---------------------- 5 files changed, 31 insertions(+), 40 deletions(-) mode change 100644 => 100755 justfile diff --git a/README.adoc b/README.adoc index ba48c28889..96190f9d43 100644 --- a/README.adoc +++ b/README.adoc @@ -653,6 +653,31 @@ $ just foo/build $ just foo/ ``` +=== Just scripts + +Just can be used as an interpreter for standalone, executable scripts. + +To do so, add a suitable shebang at the top of a justfile and make it executable: + +```sh +$ cat > script < { MixedLeadingWhitespace { whitespace: &'a str, }, - OuterShebang, ParameterFollowsVariadicParameter { parameter: &'a str, }, @@ -229,9 +228,6 @@ impl<'a> Display for CompilationError<'a> { show_whitespace(found) )?; } - OuterShebang => { - writeln!(f, "`#!` is reserved syntax outside of recipes")?; - } UnknownDependency { recipe, unknown } => { writeln!( f, diff --git a/src/lexer.rs b/src/lexer.rs index 018cb74405..abc2ea0261 100644 --- a/src/lexer.rs +++ b/src/lexer.rs @@ -135,7 +135,7 @@ impl<'a> Lexer<'a> { static ref BACKTICK: Regex = token(r"`[^`\n\r]*`"); static ref COLON: Regex = token(r":"); static ref COMMA: Regex = token(r","); - static ref COMMENT: Regex = token(r"#([^!\n\r][^\n\r]*)?\r?$"); + static ref COMMENT: Regex = token(r"#([^\n\r][^\n\r]*)?\r?$"); static ref EOF: Regex = token(r"\z"); static ref EOL: Regex = token(r"\n|\r\n"); static ref EQUALS: Regex = token(r"="); @@ -322,8 +322,6 @@ impl<'a> Lexer<'a> { return Err(self.error(UnterminatedString)); } (prefix, &self.rest[start..content_end + 1], StringToken) - } else if self.rest.starts_with("#!") { - return Err(self.error(OuterShebang)); } else { return Err(self.error(UnknownStartOfToken)); }; @@ -340,7 +338,7 @@ impl<'a> Lexer<'a> { _ => { return Err(last.error(Internal { message: format!("zero length token: {:?}", last), - })) + })); } } } @@ -647,16 +645,6 @@ c: b kind: InconsistentLeadingWhitespace{expected: "\t\t", found: "\t "}, } - error_test! { - name: tokenize_outer_shebang, - input: "#!/usr/bin/env bash", - index: 0, - line: 0, - column: 0, - width: None, - kind: OuterShebang, - } - error_test! { name: tokenize_unknown, input: "~", diff --git a/tests/integration.rs b/tests/integration.rs index 400b40e968..044c848dcd 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -578,28 +578,6 @@ wut: status: EXIT_SUCCESS, } -integration_test! { - name: outer_shebang, - justfile: r#"#!/lol/wut -export FOO = "a" -baz = "c" -export BAR = "b" -export ABC = FOO + BAR + baz - -wut: - #!/bin/sh - echo $FOO $BAR $ABC -"#, - args: (), - stdout: "", - stderr: "error: `#!` is reserved syntax outside of recipes - | -1 | #!/lol/wut - | ^ -", - status: EXIT_FAILURE, -} - integration_test! { name: export_shebang, justfile: r#" From 2e20697caf5b3d26b1f0a27420be27456a18c25d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 8 Apr 2019 13:33:31 -0700 Subject: [PATCH 2/7] Fix up docs --- README.adoc | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.adoc b/README.adoc index 96190f9d43..8db394c70d 100644 --- a/README.adoc +++ b/README.adoc @@ -655,27 +655,28 @@ $ just foo/ === Just scripts -Just can be used as an interpreter for standalone, executable scripts. +Just can be used as an interpreter for standalone executable scripts. -To do so, add a suitable shebang at the top of a justfile and make it executable: +To do so, add a suitable shebang to the top of a justfile and make it executable: ```sh $ cat > script < Date: Mon, 8 Apr 2019 13:34:27 -0700 Subject: [PATCH 3/7] Rename header --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index 8db394c70d..e2b910823f 100644 --- a/README.adoc +++ b/README.adoc @@ -653,7 +653,7 @@ $ just foo/build $ just foo/ ``` -=== Just scripts +=== Standalone Scripts Just can be used as an interpreter for standalone executable scripts. From 164e2b66bd2bd30c2dc3b5cc82133887f3806eb4 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 8 Apr 2019 13:47:53 -0700 Subject: [PATCH 4/7] Docs docs docs --- README.adoc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/README.adoc b/README.adoc index e2b910823f..b9066a0d96 100644 --- a/README.adoc +++ b/README.adoc @@ -655,9 +655,7 @@ $ just foo/ === Standalone Scripts -Just can be used as an interpreter for standalone executable scripts. - -To do so, add a suitable shebang to the top of a justfile and make it executable: +By adding a shebang line to the top of a justfile and making it executable, you can use `just` as an interpreter for standalone scripts: ```sh $ cat > script < Date: Mon, 8 Apr 2019 13:51:31 -0700 Subject: [PATCH 5/7] Docs --- README.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.adoc b/README.adoc index b9066a0d96..28ada541a7 100644 --- a/README.adoc +++ b/README.adoc @@ -672,7 +672,7 @@ foo When a script with a shebang is run, the system supplies the path to the script as an argument to the command in the shebang. So, with a shebang of `#!/usr/bin/env just --justfile`, the command will be `/usr/bin/env just --justfile PATH_TO_SCRIPT`. This allows `just` to locate and execute `justfile`. The shebang line itself will be ignored as a comment during execution. -Without `--working-directory`, `just` will change its working directory to the one containing the argument to `--justfile`. If you'd prefer to leave the working directory unchanged, use `#!/usr/bin/env just --working-directory . --justfile`. +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`. == Frequently Asked Questions From 655d8853e7a6e1e4da1f0a4eb51941e582b87219 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 8 Apr 2019 13:54:12 -0700 Subject: [PATCH 6/7] Docs --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index 28ada541a7..e1e2361a19 100644 --- a/README.adoc +++ b/README.adoc @@ -655,7 +655,7 @@ $ just foo/ === Standalone Scripts -By adding a shebang line to the top of a justfile and making it executable, you can use `just` as an interpreter for standalone scripts: +By adding a shebang line to the top of a justfile and making it executable, `just` can be used as an interpreter for standalone scripts: ```sh $ cat > script < Date: Mon, 8 Apr 2019 13:58:13 -0700 Subject: [PATCH 7/7] BLAAAAAAH --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index e1e2361a19..fa2b7b4730 100644 --- a/README.adoc +++ b/README.adoc @@ -653,9 +653,9 @@ $ just foo/build $ just foo/ ``` -=== Standalone Scripts +=== Just Scripts -By adding a shebang line to the top of a justfile and making it executable, `just` can be used as an interpreter for standalone scripts: +By adding a shebang line to the top of a justfile and making it executable, `just` can be used as an interpreter for scripts: ```sh $ cat > script <