Skip to content

Commit

Permalink
Merge branch 'master' into parse-before-load
Browse files Browse the repository at this point in the history
  • Loading branch information
neunenak authored Oct 9, 2023
2 parents 14f56fb + b068bad commit f8b4145
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 39 deletions.
53 changes: 46 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ This does not, however, preclude fixing outright bugs, even if doing so might br

There will never be a `just` 2.0. Any desirable backwards-incompatible changes will be opt-in on a per-`justfile` basis, so users may migrate at their leisure.

Features that aren't yet ready for stabilization are gated behind the `--unstable` flag. Features enabled by `--unstable` may change in backwards incompatible ways at any time.
Features that aren't yet ready for stabilization are gated behind the `--unstable` flag. Features enabled by `--unstable` may change in backwards incompatible ways at any time. Unstable features can also be enabled by setting the environment variable `JUST_UNSTABLE` to any value other than `false`, `0`, or the empty string.


Editor Support
--------------
Expand Down Expand Up @@ -356,8 +357,6 @@ cd ~/.vim/pack/vendor/start
git clone https://github.com/NoahTheDuke/vim-just.git
```

`vim-just` is also available from [vim-polyglot](https://github.com/sheerun/vim-polyglot), a multi-language Vim plugin.

#### `tree-sitter-just`

[tree-sitter-just](https://github.com/IndianBoy42/tree-sitter-just) is an [Nvim Treesitter](https://github.com/nvim-treesitter/nvim-treesitter) plugin for Neovim.
Expand Down Expand Up @@ -424,6 +423,10 @@ Kakoune supports `justfile` syntax highlighting out of the box, thanks to TeddyD

The [Just package](https://github.com/nk9/just_sublime) by [nk9](https://github.com/nk9) with `just` syntax and some other tools is available on [PackageControl](https://packagecontrol.io/packages/Just).

### Micro

[Micro](https://micro-editor.github.io/) supports Justfile syntax highlighting out of the box, thanks to [tomodachi94](https://github.com/tomodachi94).

### Other Editors

Feel free to send me the commands necessary to get syntax highlighting working in your editor of choice so that I may include them here.
Expand Down Expand Up @@ -910,7 +913,7 @@ Starting server with database localhost:6379 on port 1337…
Variables, strings, concatenation, path joining, and substitution using `{{…}}` are supported:

```just
tmpdir := `mktemp`
tmpdir := `mktemp -d`
version := "0.2.7"
tardir := tmpdir / "awesomesauce-" + version
tarball := tardir + ".tar.gz"
Expand Down Expand Up @@ -1035,7 +1038,7 @@ $ just --evaluate
escapes := "\t\n\r\"\\"
```

Indented versions of both single- and double-quoted strings, delimited by triple single- or triple double-quotes, are supported. Indented string lines are stripped of leading whitespace common to all non-blank lines:
Indented versions of both single- and double-quoted strings, delimited by triple single- or triple double-quotes, are supported. Indented string lines are stripped of a leading line break, and leading whitespace common to all non-blank lines:

```just
# this string will evaluate to `foo\nbar\n`
Expand All @@ -1044,7 +1047,7 @@ x := '''
bar
'''
# this string will evaluate to `abc\n wuv\nbar\n`
# this string will evaluate to `abc\n wuv\nxyz\n`
y := """
abc
wuv
Expand Down Expand Up @@ -1917,7 +1920,43 @@ foo:

### Indentation

Recipe lines can be indented with spaces or tabs, but not a mix of both. All of a recipe's lines must have the same indentation, but different recipes in the same `justfile` may use different indentation.
Recipe lines can be indented with spaces or tabs, but not a mix of both. All of a recipe's lines must have the same type of indentation, but different recipes in the same `justfile` may use different indentation.

Each recipe must be indented at least one level from the `recipe-name` but after that may be further indented.

Here's a justfile with a recipe indented with spaces, represented as `·`, and tabs, represented as ``.

```justfile
set windows-shell := ["pwsh", "-NoLogo", "-NoProfileLoadTime", "-Command"]
set ignore-comments
list-space directory:
··#!pwsh
··foreach ($item in $(Get-ChildItem {{directory}} )) {
····echo $item.Name
··}
··echo ""
# indentation nesting works even when newlines are escaped
list-tab directory:
→ @foreach ($item in $(Get-ChildItem {{directory}} )) { \
→ → echo $item.Name \
→ }
→ @echo ""
```

```pwsh
PS > just list-space ~
Desktop
Documents
Downloads
PS > just list-tab ~
Desktop
Documents
Downloads
```

### Multi-Line Constructs

Expand Down
4 changes: 1 addition & 3 deletions README.中文.md
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,6 @@ cd ~/.vim/pack/vendor/start
git clone https://github.com/NoahTheDuke/vim-just.git
```

`vim-just` 也可以从 [vim-polyglot](https://github.com/sheerun/vim-polyglot) 获得,这是一个多语言的 Vim 插件。

#### `tree-sitter-just`

[tree-sitter-just](https://github.com/IndianBoy42/tree-sitter-just) 是一个针对 Neovim 的 [Nvim Treesitter](https://github.com/nvim-treesitter/nvim-treesitter) 插件。
Expand Down Expand Up @@ -890,7 +888,7 @@ Starting server with database localhost:6379 on port 1337…
支持在变量、字符串、拼接、路径连接和替换中使用 `{{…}}`

```just
tmpdir := `mktemp`
tmpdir := `mktemp -d`
version := "0.2.7"
tardir := tmpdir / "awesomesauce-" + version
tarball := tardir + ".tar.gz"
Expand Down
3 changes: 3 additions & 0 deletions bin/generate-completions
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@ set -euxo pipefail

for script in completions/*; do
shell=${script##*.}
if [ $shell == nu ]; then
continue
fi
cargo run -- --completions $shell > $script
done
8 changes: 8 additions & 0 deletions completions/just.nu
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def "nu-complete just" [] {
(^just --dump --unstable --dump-format json | from json).recipes | transpose recipe data | flatten | where {|row| $row.private == false } | select recipe doc parameters | rename value description
}

# Just: A Command Runner
export extern "just" [
...recipe: string@"nu-complete just", # Recipe(s) to run, may be with argument(s)
]
12 changes: 6 additions & 6 deletions src/completions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ pub(crate) const ZSH_COMPLETION_REPLACEMENTS: &[(&str, &str)] = &[
r#" local common=("#,
),
(
r#"'*--set=[Override <VARIABLE> with <VALUE>]' \"#,
r#"'*--set[Override <VARIABLE> with <VALUE>]: :_just_variables' \"#,
r"'*--set=[Override <VARIABLE> with <VALUE>]' \",
r"'*--set[Override <VARIABLE> with <VALUE>]: :_just_variables' \",
),
(
r#"'-s+[Show information about <RECIPE>]' \
'--show=[Show information about <RECIPE>]' \"#,
r#"'-s+[Show information about <RECIPE>]: :_just_commands' \
'--show=[Show information about <RECIPE>]: :_just_commands' \"#,
r"'-s+[Show information about <RECIPE>]' \
'--show=[Show information about <RECIPE>]' \",
r"'-s+[Show information about <RECIPE>]: :_just_commands' \
'--show=[Show information about <RECIPE>]: :_just_commands' \",
),
(
"'::ARGUMENTS -- Overrides and recipe(s) to run, defaulting to the first recipe in the \
Expand Down
7 changes: 6 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,11 @@ impl Config {
None
};

let unstable = matches.is_present(arg::UNSTABLE)
|| std::env::var_os("JUST_UNSTABLE")
.map(|val| !(val == "false" || val == "0" || val.is_empty()))
.unwrap_or_default();

Ok(Self {
check: matches.is_present(arg::CHECK),
dry_run: matches.is_present(arg::DRY_RUN),
Expand All @@ -578,7 +583,7 @@ impl Config {
load_dotenv: !matches.is_present(arg::NO_DOTENV),
shell_command: matches.is_present(arg::SHELL_COMMAND),
unsorted: matches.is_present(arg::UNSORTED),
unstable: matches.is_present(arg::UNSTABLE),
unstable,
list_heading: matches
.value_of(arg::LIST_HEADING)
.unwrap_or("Available recipes:\n")
Expand Down
6 changes: 3 additions & 3 deletions src/justfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,13 @@ foo +a="Hello":

test! {
parse_raw_string_default,
r#"
r"
foo a='b\t':
"#,
r#"foo a='b\t':"#,
",
r"foo a='b\t':",
}

test! {
Expand Down
12 changes: 6 additions & 6 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1440,23 +1440,23 @@ mod tests {

test! {
name: indented_backtick,
text: r#"
text: r"
x := ```
\tfoo\t
\tbar\n
```
"#,
",
tree: (justfile (assignment x (backtick "\\tfoo\\t\n\\tbar\\n\n"))),
}

test! {
name: indented_backtick_no_dedent,
text: r#"
text: r"
x := ```
\tfoo\t
\tbar\n
```
"#,
",
tree: (justfile (assignment x (backtick "\\tfoo\\t\n \\tbar\\n\n"))),
}

Expand Down Expand Up @@ -1495,12 +1495,12 @@ mod tests {

test! {
name: parse_raw_string_default,
text: r#"
text: r"
foo a='b\t':
"#,
",
tree: (justfile (recipe foo (params (a "b\\t")))),
}

Expand Down
1 change: 1 addition & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ mod string;
mod subsequents;
mod tempdir;
mod undefined_variables;
mod unstable;
#[cfg(target_family = "windows")]
mod windows_shell;
mod working_directory;
Expand Down
12 changes: 6 additions & 6 deletions tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,36 +1000,36 @@ a Z="\t z":

test! {
name: line_continuation_with_space,
justfile: r#"
justfile: r"
foo:
echo a\
b \
c
"#,
",
stdout: "ab c\n",
stderr: "echo ab c\n",
}

test! {
name: line_continuation_with_quoted_space,
justfile: r#"
justfile: r"
foo:
echo 'a\
b \
c'
"#,
",
stdout: "ab c\n",
stderr: "echo 'ab c'\n",
}

test! {
name: line_continuation_no_space,
justfile: r#"
justfile: r"
foo:
echo a\
b\
c
"#,
",
stdout: "abc\n",
stderr: "echo abc\n",
}
Expand Down
12 changes: 6 additions & 6 deletions tests/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,19 +318,19 @@ test! {

test! {
name: indented_raw_string_escapes,
justfile: r#"
justfile: r"
a := '''
foo\n
bar
'''
@default:
printf %s '{{a}}'
"#,
stdout: r#"
",
stdout: r"
foo\n
bar
"#,
",
}

test! {
Expand All @@ -353,7 +353,7 @@ test! {

test! {
name: indented_backtick_string_escapes,
justfile: r#"
justfile: r"
a := ```
printf %s '
foo\n
Expand All @@ -363,7 +363,7 @@ test! {
@default:
printf %s '{{a}}'
"#,
",
stdout: "\n\nfoo\\n\nbar",
}

Expand Down
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl Test {

if let Some(ref stdout_regex) = self.stdout_regex {
if !stdout_regex.is_match(output_stdout) {
panic!("Stdout regex mismatch:\n{output_stderr:?}\n!~=\n/{stdout_regex:?}/");
panic!("Stdout regex mismatch:\n{output_stdout:?}\n!~=\n/{stdout_regex:?}/");
}
}

Expand Down
50 changes: 50 additions & 0 deletions tests/unstable.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
use super::*;

#[test]
fn set_unstable_true_with_env_var() {
let justfile = r#"
default:
echo 'foo'
"#;

for val in ["true", "some-arbitrary-string"] {
Test::new()
.justfile(justfile)
.args(["--fmt"])
.env("JUST_UNSTABLE", val)
.status(EXIT_SUCCESS)
.stderr_regex("Wrote justfile to `.*`\n")
.run();
}
}

#[test]
fn set_unstable_false_with_env_var() {
let justfile = r#"
default:
echo 'foo'
"#;
for val in ["0", "", "false"] {
Test::new()
.justfile(justfile)
.args(["--fmt"])
.env("JUST_UNSTABLE", val)
.status(EXIT_FAILURE)
.stderr("error: The `--fmt` command is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n")
.run();
}
}

#[test]
fn set_unstable_false_with_env_var_unset() {
let justfile = r#"
default:
echo 'foo'
"#;
Test::new()
.justfile(justfile)
.args(["--fmt"])
.status(EXIT_FAILURE)
.stderr("error: The `--fmt` command is currently unstable. Invoke `just` with the `--unstable` flag to enable unstable features.\n")
.run();
}

0 comments on commit f8b4145

Please sign in to comment.