-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.nu
executable file
·201 lines (174 loc) · 6.63 KB
/
run.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env nu
# nu shell docs
# - language fundamentals: https://www.nushell.sh/book/custom_commands.html#sub-commands
# - strings: https://www.nushell.sh/book/working_with_strings.html#string-interpolation
# - functions (aka commands, subcommands): https://www.nushell.sh/book/custom_commands.html
# - variables: https://www.nushell.sh/book/variables_and_subexpressions.html
# - built-in command reference: https://www.nushell.sh/commands/#command-reference
# - length: https://www.nushell.sh/commands/docs/length.html
# - ansi: https://www.nushell.sh/commands/docs/ansi.html
# - print: https://www.nushell.sh/commands/docs/print.html
# - input: https://www.nushell.sh/commands/docs/input.html
# - input list: https://www.nushell.sh/commands/docs/input_list.html
# - match: https://www.nushell.sh/commands/docs/match.html
# - mental model
# - coming from bash: https://www.nushell.sh/book/coming_from_bash.html
# - thinking in nu: https://www.nushell.sh/book/thinking_in_nu.html
# Main entry point for the script.
def main [...args: string] {
let num_args = $args | length
if $num_args == 0 {
print-help all
return
}
let command = $args | get 0
match $command {
"watch-one-test" => {watch-one-test $args}
"watch-macro-expansion-one-test" => {watch-macro-expansion-one-test $args}
"all" => {all}
"build" => {build}
"clean" => {clean}
"run" => {run}
"run-with-flamegraph-profiling" => {run-with-flamegraph-profiling}
"watch-run" => {watch-run}
"test" => {test}
"watch-all-tests" => {watch-all-tests}
"clippy" => {clippy}
"watch-clippy" => {watch-clippy}
"docs" => {docs}
"serve-docs" => {serve-docs}
"upgrade-deps" => {upgrade-deps}
"rustfmt" => {rustfmt}
"help" => {print-help all}
_ => {print $'Unknown command: (ansi red_bold)($command)(ansi reset)'}
}
}
# Watch a single test. This expects the test name to be passed in as an argument.
# If it isn't passed in, it will prompt the user for it.
def watch-one-test [args: list<string>] {
let num_args = $args | length
let test_name = if $num_args == 2 {
let test_name = $args | get 1
$test_name
} else {
print-help watch-one-test
let user_input = (input "Enter the test-name: " )
$user_input
}
if $test_name != "" {
# More info on cargo test: https://doc.rust-lang.org/cargo/commands/cargo-test.html
# More info on cargo watch: https://github.com/watchexec/cargo-watch
let command_string = "test -- --test-threads=1 --nocapture " + $test_name
cargo watch -x check -x $command_string -c -q
} else {
print $'Can not run this command without (ansi red_bold)test_name(ansi reset)'
}
}
# Watch a single test. This expects the test name to be passed in as an argument.
# If it isn't passed in, it will prompt the user for it.
def watch-macro-expansion-one-test [args: list<string>] {
let num_args = $args | length
let test_name = if $num_args == 2 {
let test_name = $args | get 1
$test_name
} else {
print-help watch-macro-expansion-one-test
let user_input = (input "Enter the test-name: " )
$user_input
}
if $test_name != "" {
let command_string = "expand --test " + $test_name
cargo watch -x $command_string -c -q -d 1
} else {
print $'Can not run this command without (ansi red_bold)test_name(ansi reset)'
}
}
# Prints help for the script.
# - If "all" is passed in, prints help for all commands.
# - Otherwise, prints help for the specified command.
def print-help [command: string] {
if $command == "all" {
print $'Usage: (ansi blue_bold)run.nu(ansi reset) (ansi green_bold)<command>(ansi reset) (ansi yellow)[args](ansi reset)'
print $'(ansi green_bold)<command>(ansi reset) can be:'
print $' (ansi green)all(ansi reset)'
print $' (ansi green)build(ansi reset)'
print $' (ansi green)clean(ansi reset)'
print $' (ansi green)run(ansi reset)'
print $' (ansi green)run-with-flamegraph-profiling(ansi reset)'
print $' (ansi green)watch-run(ansi reset)'
print $' (ansi green)test(ansi reset)'
print $' (ansi green)watch-one-test(ansi reset) (ansi blue_bold)<test-name>(ansi reset)'
print $' (ansi green)watch-all-tests(ansi reset)'
print $' (ansi green)clippy(ansi reset)'
print $' (ansi green)watch-clippy(ansi reset)'
print $' (ansi green)docs(ansi reset)'
print $' (ansi green)watch-macro-expansion-one-test(ansi reset) (ansi blue_bold)<test-name>(ansi reset)'
print $' (ansi green)serve-docs(ansi reset)'
print $' (ansi green)upgrade-deps(ansi reset)'
print $' (ansi green)rustfmt(ansi reset)'
print $' (ansi green)help(ansi reset)'
} else if $command == "watch-one-test" {
print $'Usage: (ansi blue_bold)run.nu(ansi reset) (ansi green_bold)watch-one-test(ansi reset) (ansi yellow)<test-name>(ansi reset)'
print $' (ansi green)<test-name>(ansi reset) is the name of the test to watch.'
} else if $command == "watch-macro-expansion-one-test" {
print $'Usage: (ansi blue_bold)run.nu(ansi reset) (ansi green_bold)watch-macro-expansion-one-test(ansi reset) (ansi yellow)<test-name>(ansi reset)'
print $' (ansi green)<test-name>(ansi reset) is the name of the test to watch.'
} else {
print $'Unknown command: (ansi red_bold)($command)(ansi reset)'
}
}
def all [] {
clean
build
test
clippy
docs
rustfmt
}
def build [] {
cargo build
}
def clean [] {
cargo clean
}
def run [] {
cargo run --example main
}
def run-release [] {
cargo run --release --example main
}
def run-with-flamegraph [] {
cargo flamegraph --example main
}
def watch-run [] {
cargo watch -- cargo run --example main
}
def test [] {
cargo test
}
def watch-all-tests [] {
cargo watch --exec check --exec 'test --quiet --color always -- --test-threads 1' --clear --quiet --delay 1
}
def clippy [] {
cargo clippy --all-targets --all-features -- -D warnings
}
def watch-clippy [] {
cargo fix --allow-dirty --allow-staged
cargo fmt --all
cargo watch -x 'clippy --fix --allow-dirty --allow-staged' -c -q
}
def docs [] {
cargo doc --no-deps --all-features
}
def serve-docs [] {
npm i -g serve
serve target/doc
}
def upgrade-deps [] {
cargo outdated --workspace --verbose
cargo upgrade --to-lockfile --verbose
cargo update
}
def rustfmt [] {
cargo fmt --all
}