Skip to content

Commit 2666cfc

Browse files
committed
doc: setup guidance updates, scripts formatted with the new style
1 parent eb107d7 commit 2666cfc

File tree

4 files changed

+104
-49
lines changed

4 files changed

+104
-49
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Change Log
2+
3+
All style related breaking changes will be documented in this file.
4+
5+
### [eb107d7] (<https://github.com/blindFS/topiary-nushell/commit/eb107d753c687311ce1f09f68963d482c3d4335b>) feat(style)!: +1 indentation level for multiline pipelines in assignment-like expressions
6+
7+
Related issue: [#43](https://github.com/blindFS/topiary-nushell/issues/43)
8+
9+
#### Before the change
10+
11+
```nushell
12+
let config: path = $config
13+
| default (
14+
$toplevel
15+
| path join .cargo nextest.toml
16+
)
17+
```
18+
19+
#### After the change
20+
21+
```nushell
22+
let config: path = $config
23+
| default (
24+
$toplevel
25+
| path join .cargo nextest.toml
26+
)
27+
```

README.md

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@
1010

1111
## Status
1212

13-
* Supposed to work well with all language features of nushell v0.108
13+
* Supposed to work well with all language features of nushell v0.109
1414
* Except for some known issues of `tree-sitter-nu`
1515

1616
> [!NOTE]
1717
>
1818
> * There're corner cases where `tree-sitter-nu` would fail with parsing errors, if you encounter any, feel free to report [at the parser side](https://github.com/nushell/tree-sitter-nu/issues).
1919
> * If you encounter any style/format issue, please report in this repo.
20+
> * At this stage, the default style of nu-lang has no consensus yet, related breaking changes will be documented in [CHANGELOG.md](https://github.com/blindFS/topiary-nushell/blob/main/CHANGELOG.md).
2021
21-
## Setup
22+
## Quick Setup
23+
24+
> [!NOTE]
25+
> This section is for nushell users who have little experience with topiary.
26+
> If you are already an experienced topiary user, you can grab the necessary files in this repo and merge them into your topiary configuration in your own preferred way.
2227
2328
1. Install topiary-cli using whatever package-manager on your system (0.7.0+ required)
2429

@@ -29,17 +34,21 @@ cargo install topiary-cli
2934

3035
2. Clone this repo somewhere
3136

37+
`$env.XDG_CONFIG_HOME/topiary` is recommended for non-windows users.
38+
3239
```nushell
33-
# e.g. to `$env.XDG_CONFIG_HOME/topiary`
3440
git clone https://github.com/blindFS/topiary-nushell ($env.XDG_CONFIG_HOME | path join topiary)
3541
```
3642

3743
3. Setup environment variables (Optional)
3844

3945
> [!WARNING]
40-
> This is required if you want to do the formatting via vanilla topiary-cli, like in the neovim/helix settings below.
46+
> This is required if:
47+
>
48+
> 1. on windows
49+
> 2. this repo is cloned to a place other than `$env.XDG_CONFIG_HOME/topiary`
4150
>
42-
> While the [`format.nu`](https://github.com/blindFS/topiary-nushell/blob/main/format.nu) script in this repo just wraps that for you.
51+
> Take the [`format.nu`](https://github.com/blindFS/topiary-nushell/blob/main/format.nu) script in this repo as an example.
4352
4453
```nushell
4554
# Set environment variables according to the path of the clone
@@ -76,8 +85,20 @@ $env.TOPIARY_LANGUAGE_DIR = ($env.XDG_CONFIG_HOME | path join topiary languages)
7685
## Usage
7786

7887
<details>
79-
<summary>Using the <a href="https://github.com/blindFS/topiary-nushell/blob/main/format.nu">format.nu</a> wrapper </summary>
88+
<summary>Using topiary-cli (recommended) </summary>
8089

90+
```nushell
91+
# in-place formatting
92+
topiary format script.nu
93+
# stdin -> stdout
94+
cat foo.nu | topiary format --language nu
95+
```
96+
97+
</details>
98+
99+
<details>
100+
<summary>Using the <a href="https://github.com/blindFS/topiary-nushell/blob/main/format.nu">format.nu</a> wrapper </summary>
101+
81102
```markdown
82103
Helper to run topiary with the correct environment variables for topiary-nushell
83104

@@ -112,18 +133,6 @@ Examples:
112133

113134
</details>
114135

115-
<details>
116-
<summary>Using topiary-cli </summary>
117-
118-
```nushell
119-
# in-place formatting
120-
topiary format script.nu
121-
# stdin -> stdout
122-
cat foo.nu | topiary format --language nu
123-
```
124-
125-
</details>
126-
127136
### Locally Disable Formatting for Certain Expression
128137

129138
If you don't like the formatted output of certain parts of your code,
@@ -192,7 +201,8 @@ formatter = { command = "topiary", args = ["format", "--language", "nu"] }
192201
"Nu": {
193202
"formatter": {
194203
"external": {
195-
"command": "/path-to-the-clone/format.nu"
204+
"command": "topiary",
205+
"arguments": ["format", "--language", "nu"]
196206
}
197207
},
198208
"format_on_save": "on"

run_test.nu

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,33 @@ let files = glob test/input_*.nu
88
$env.TOPIARY_CONFIG_FILE = (pwd | path join languages.ncl)
99
$env.TOPIARY_LANGUAGE_DIR = (pwd | path join languages)
1010

11-
for f in $files {
12-
print $"(ansi green)Testing: (ansi yellow)($f)(ansi reset)"
13-
cp $f $temp_file
14-
topiary format $temp_file
15-
let expected_file = $f | str replace --regex '/input_' '/expected_'
16-
try {
17-
assert ((open $temp_file) == (open $expected_file))
18-
} catch {
19-
delta $temp_file $expected_file
11+
def main [
12+
--update (-u) # force updating `expected_xxx` files
13+
] {
14+
for f in $files {
15+
print $"(ansi green)Testing: (ansi yellow)($f)(ansi reset)"
16+
cp $f $temp_file
17+
topiary format $temp_file
18+
let expected_file = $f | str replace --regex '/input_' '/expected_'
19+
try {
20+
if ((which delta) | is-empty) {
21+
assert ((open $temp_file) == (open $expected_file))
22+
} else {
23+
delta $temp_file $expected_file --paging never
24+
}
25+
} catch {
26+
if $update and (
27+
[yes no]
28+
| input list --index --fuzzy $"Update expected results in file (
29+
$expected_file
30+
| path basename
31+
)?"
32+
) == 0 {
33+
cp $temp_file $expected_file
34+
} else {
35+
exit 1
36+
}
37+
}
38+
rm $temp_file
2039
}
21-
rm $temp_file
2240
}

toolkit.nu

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,27 @@ export def test_format [
4646
return
4747
}
4848
let all_passed = 1..$len | par-each {|i|
49-
let file = $files | get ($i - 1)
50-
let target = $"(random uuid).nu"
51-
if ($i mod 10) == 0 {
52-
print -n $"(ansi -e '1000D')"
53-
print_progress ($i / $len)
49+
let file = $files | get ($i - 1)
50+
let target = $"(random uuid).nu"
51+
if ($i mod 10) == 0 {
52+
print -n $"(ansi -e '1000D')"
53+
print_progress ($i / $len)
54+
}
55+
let failed = try {
56+
cp $file $target
57+
let err_before = run_ide_check $target
58+
topiary format $target
59+
let err_after = run_ide_check $target
60+
assert ($err_before == $err_after)
61+
true
62+
} catch {
63+
print $"(ansi red)Error detected: (ansi yellow)($file)(ansi reset)"
64+
false
65+
}
66+
rm $target
67+
$failed
5468
}
55-
let failed = try {
56-
cp $file $target
57-
let err_before = run_ide_check $target
58-
topiary format $target
59-
let err_after = run_ide_check $target
60-
assert ($err_before == $err_after)
61-
true
62-
} catch {
63-
print $"(ansi red)Error detected: (ansi yellow)($file)(ansi reset)"
64-
false
65-
}
66-
rm $target
67-
$failed
68-
}
69-
| all { $in }
69+
| all { $in }
7070
if $all_passed {
7171
print -n $"(ansi -e '1000D')"
7272
print $"(ansi green)All nu scripts successfully passed the check, but style issues are still possible.(ansi reset)"

0 commit comments

Comments
 (0)