Skip to content
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

feat: add usage field to tasks #3746

Merged
merged 3 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add usage field to tasks
  • Loading branch information
jdx committed Dec 21, 2024
commit 09eeeb33efb87349b00b4ee05d3f80e9634252c9
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions docs/tasks/task-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,20 @@ like to hide even the output that the task emits, use [`silent`](#silent).

Suppress all output from the task. If set to `"stdout"` or `"stderr"`, only that stream will be suppressed.

### `usage`

- **Type**: `string`

More advanced usage specs can be added to the task's `usage` field. This only applies to toml-tasks.

```toml
[tasks.test]
usage = '''
arg "file" description="The file to test" default="src/main.rs"
'''
run = 'cargo test {{arg(name="file")}}'
```

## Vars

Vars are variables that can be shared between tasks like environment variables but they are not
Expand Down
12 changes: 12 additions & 0 deletions docs/tasks/toml-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,15 @@ fi
- `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.

### Usage spec

More advanced usage specs can be added to the task's `usage` field:

```toml
[tasks.test]
usage = '''
arg "file" description="The file to test" default="src/main.rs"
'''
run = 'cargo test {{arg(name="file")}}'
```
9 changes: 9 additions & 0 deletions e2e/tasks/test_task_run_toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ assert "mise run -E windows configtask" "configtask:windows"
assert "mise run -P windows configtask" "configtask:windows"
MISE_ENV=windows assert "mise run configtask" "configtask:windows"
MISE_PROFILE=windows assert "mise run configtask" "configtask:windows"

cat <<EOF >mise.toml
[tasks.a]
usage = '''
arg "myarg" "myarg description" default="foo"
'''
run = 'echo {{arg(name="myarg")}}'
EOF
assert "mise run a" "foo"
2 changes: 1 addition & 1 deletion mise.lock
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ version = "0.2.3"
backend = "cargo:toml-cli"

[tools."cargo:usage-cli"]
version = "1.7.3"
version = "1.7.4"
backend = "cargo:usage-cli"

[tools.cosign]
Expand Down
12 changes: 0 additions & 12 deletions src/cli/config/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,11 @@ impl ConfigSet {
let mut container = config.as_item_mut();
let parts = self.key.split('.').collect::<Vec<&str>>();
for key in parts.iter().take(parts.len() - 1) {
<<<<<<< HEAD
container = container.as_table_mut().unwrap().entry(key).or_insert({
let mut t = toml_edit::Table::new();
t.set_implicit(true);
toml_edit::Item::Table(t)
});
=======
container = container
.as_table_mut()
.unwrap()
.entry(key)
.or_insert({
let mut t = toml_edit::Table::new();
t.set_implicit(true);
toml_edit::Item::Table(t)
});
>>>>>>> 01bd9dbb2 (fix: use implicit keys for `mise config set`)
}
let last_key = parts.last().unwrap();

Expand Down
3 changes: 3 additions & 0 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct Task {
pub silent: bool,
#[serde(default)]
pub tools: IndexMap<String, String>,
#[serde(default)]
pub usage: String,

// normal type
#[serde(default, deserialize_with = "deserialize_arr")]
Expand Down Expand Up @@ -562,6 +564,7 @@ impl Default for Task {
file: None,
quiet: false,
tools: Default::default(),
usage: "".to_string(),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/task/task_script_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,11 @@ impl TaskScriptParser {
})
.collect();
cmd.flags = input_flags.lock().unwrap().clone();
let spec = usage::Spec {
let mut spec = usage::Spec {
cmd,
..Default::default()
};
spec.merge(task.usage.parse()?);

Ok((scripts, spec))
}
Expand Down
Loading