-
Notifications
You must be signed in to change notification settings - Fork 323
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
Changes from 3 commits
b4523cc
c70356d
1a2236b
4f72f90
4402938
d3e43f7
3503311
8b8e6ea
ac1d845
6685c06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,60 @@ 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 | ||||||||
|
||||||||
You can specify a shell command to run the script with (default is `sh -c`). | ||||||||
|
||||||||
```toml | ||||||||
[tasks.lint] | ||||||||
shell = 'bash -c' | ||||||||
run = "cargo clippy" | ||||||||
``` | ||||||||
|
||||||||
Here is another example with `deno`: | ||||||||
|
||||||||
```toml | ||||||||
[tools] | ||||||||
deno = 'latest' | ||||||||
|
||||||||
[tasks.download_task] | ||||||||
description = "Shows that you can use deno in a task" | ||||||||
shell = 'deno eval' | ||||||||
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. while this works, it can also be done with a shebang: run = """
#!/usr/bin/env -S deno run --allow-env
""" which I prefer even though users need to understand 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. I don't know this for sure, but I suspect a shebang would also be easier for IDEs to syntax highlight, so I think that should be our preferred method here 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. 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. Ah wait, this is mise/src/task/task_script_parser.rs Lines 312 to 314 in d5781be
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. I think that is only partially done, the shell_type there is only used for knowing whether or not it should escape args but I plan to soon make it actually parse and execute the shebang directly instead of going through 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. if only I knew the mise-vscode maintainer ;) 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. I do think syntax highlighting with shebangs would be a killer feature, or even if you got it to default to multiline strings as bash 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. btw we should add your extension to the docs 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. Sure, I will make a PR next week. Want to check the windows support first 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. might be worth waiting until I get the shebang parsing fully in place—right now it almost certainly will fail with any shebang—though a user could work around that with run_windows |
||||||||
run = """ | ||||||||
import ProgressBar from "jsr:@deno-library/progress"; | ||||||||
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 download_task | ||||||||
# [download_task] $ import ProgressBar from "jsr:@deno-library/progress"; | ||||||||
# Start download? [y/N] y | ||||||||
# downloading: ... | ||||||||
``` | ||||||||
|
||||||||
## Windows | ||||||||
|
||||||||
You can specify an alternate command to run on Windows by using the `run_windows` key: | ||||||||
|
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.
seems like a missed opportunity to show how multiline strings work in toml. The comma at the end is also a syntax error