-
-
Notifications
You must be signed in to change notification settings - Fork 430
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
docs: Add more examples for toml tasks #3491
Merged
Merged
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b4523cc
docs: Add more examples for toml tasks
hverlin c70356d
update
hverlin 1a2236b
[autofix.ci] apply automated fixes
autofix-ci[bot] 4f72f90
fix
hverlin 4402938
update
hverlin d3e43f7
update
hverlin 3503311
[autofix.ci] apply automated fixes
autofix-ci[bot] 8b8e6ea
code group
hverlin ac1d845
wip
hverlin 6685c06
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -27,8 +27,6 @@ dir = "{{cwd}}" # run in user's cwd, default is the project's base directory | |||||||||||||
[tasks.lint] | ||||||||||||||
description = 'Lint with clippy' | ||||||||||||||
env = { RUST_BACKTRACE = '1' } # env vars for the script | ||||||||||||||
# specify a shell command to run the script with (default is 'sh -c') | ||||||||||||||
shell = 'bash -c' | ||||||||||||||
# you can specify a multiline script instead of individual commands | ||||||||||||||
run = """ | ||||||||||||||
#!/usr/bin/env bash | ||||||||||||||
|
@@ -134,7 +132,7 @@ run = 'cargo test {{option(name="file")}}' | |||||||||||||
Flags are like options except they don't take values. They are defined in scripts with <span v-pre> | ||||||||||||||
`{{flag()}}`</span>. | ||||||||||||||
|
||||||||||||||
Example: | ||||||||||||||
Examples: | ||||||||||||||
|
||||||||||||||
```toml | ||||||||||||||
[tasks.echo] | ||||||||||||||
|
@@ -143,10 +141,125 @@ run = 'echo {{flag(name=("myflag")}}' | |||||||||||||
# runs: echo true | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```toml | ||||||||||||||
[tasks.maybeClean] | ||||||||||||||
run = """ | ||||||||||||||
if [ '{{flag(name='clean')}}' = 'true' ]; then | ||||||||||||||
echo 'cleaning' | ||||||||||||||
fi | ||||||||||||||
""" | ||||||||||||||
# execute: mise run maybeClean --clean | ||||||||||||||
# runs: echo cleaning | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
- `name`: The name of the flag. This is used for help/error messages. | ||||||||||||||
|
||||||||||||||
The value will be `true` if the flag is passed, and `false` otherwise. | ||||||||||||||
|
||||||||||||||
## Shell / Shebang | ||||||||||||||
|
||||||||||||||
You can specify a shell command to run the script with (default is [`sh -c`](/configuration/settings.html#unix_default_inline_shell_args) or [`cmd /c`](/configuration/settings.html#windows_default_inline_shell_args)) or use a shebang: | ||||||||||||||
|
||||||||||||||
```toml | ||||||||||||||
[tasks.lint] | ||||||||||||||
shell = 'bash -c' | ||||||||||||||
run = "cargo clippy" | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
or use a shebang: | ||||||||||||||
|
||||||||||||||
```toml | ||||||||||||||
[tasks.lint] | ||||||||||||||
run = """ | ||||||||||||||
#!/usr/bin/env bash | ||||||||||||||
cargo clippy | ||||||||||||||
""" | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
By using `shell` or `shebang`, you can run scripts in different languages: | ||||||||||||||
|
||||||||||||||
::: code-group | ||||||||||||||
|
||||||||||||||
```toml [python] | ||||||||||||||
[tools] | ||||||||||||||
python = 'latest' | ||||||||||||||
|
||||||||||||||
[tasks.python_task] | ||||||||||||||
run = """ | ||||||||||||||
#!/usr/bin/env -S python | ||||||||||||||
for i in range(10): | ||||||||||||||
print(i) | ||||||||||||||
""" | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```toml [node] | ||||||||||||||
[tools] | ||||||||||||||
node = 'lts' | ||||||||||||||
|
||||||||||||||
[tasks.node_task] | ||||||||||||||
shell = 'node -e' | ||||||||||||||
run = [ | ||||||||||||||
"console.log('First line')", | ||||||||||||||
"console.log('Second line')", | ||||||||||||||
] | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```toml [bun] | ||||||||||||||
[tools] | ||||||||||||||
bun = 'latest' | ||||||||||||||
|
||||||||||||||
[tasks.bun_shell] | ||||||||||||||
shell = "bun -e" | ||||||||||||||
run = """ | ||||||||||||||
// https://bun.sh/docs/runtime/shell | ||||||||||||||
import { $ } from "bun"; | ||||||||||||||
const response = await fetch("https://example.com"); | ||||||||||||||
await $`cat < ${response} | wc -c`; // 1256 | ||||||||||||||
""" | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```toml [deno] | ||||||||||||||
[tools] | ||||||||||||||
deno = 'latest' | ||||||||||||||
|
||||||||||||||
[tasks.deno_task] | ||||||||||||||
description = "Shows that you can use deno in a task" | ||||||||||||||
shell = 'deno eval' # or use a shebang: #!/usr/bin/env -S deno run | ||||||||||||||
run = """ | ||||||||||||||
import ProgressBar from "jsr:@deno-library/progress"; | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry, this is what I meant
Suggested change
|
||||||||||||||
import { delay } from "jsr:@std/async"; | ||||||||||||||
|
||||||||||||||
if (!confirm('Start download?')) { | ||||||||||||||
Deno.exit(1); | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
const progress = new ProgressBar({ title: "downloading:", total: 100 }); | ||||||||||||||
let completed = 0; | ||||||||||||||
async function download() { | ||||||||||||||
while (completed <= 100) { | ||||||||||||||
await progress.render(completed++); | ||||||||||||||
await delay(10); | ||||||||||||||
} | ||||||||||||||
} | ||||||||||||||
await download(); | ||||||||||||||
""" | ||||||||||||||
# ❯ mise run deno_task | ||||||||||||||
# [download_task] $ import ProgressBar from "jsr:@deno-library/progress"; | ||||||||||||||
# Start download? [y/N] y | ||||||||||||||
# downloading: ... | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
```toml [ruby] | ||||||||||||||
[tools] | ||||||||||||||
ruby = 'latest' | ||||||||||||||
|
||||||||||||||
[tasks.ruby_task] | ||||||||||||||
shell = 'ruby -e' | ||||||||||||||
run = "puts 'Hello, world!'" | ||||||||||||||
``` | ||||||||||||||
|
||||||||||||||
::: | ||||||||||||||
|
||||||||||||||
## Windows | ||||||||||||||
|
||||||||||||||
You can specify an alternate command to run on Windows by using the `run_windows` key: | ||||||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should reserve
env -S
for shebangs that have multiple args (likedeno run
). We should also document on this page what the heckenv -S
does in a callout of some kind. I suspect most users won't have a clue what it means. I think I already do that in the tips and tricks doc but this page is going to be far more heavily trafficked.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I will update 👍