mirror of
https://github.com/nushell/nushell.git
synced 2025-08-15 12:43:14 +02:00
Allow plugins to report their own version and store it in the registry (#12883)
# Description This allows plugins to report their version (and potentially other metadata in the future). The version is shown in `plugin list` and in `version`. The metadata is stored in the registry file, and reflects whatever was retrieved on `plugin add`, not necessarily the running binary. This can help you to diagnose if there's some kind of mismatch with what you expect. We could potentially use this functionality to show a warning or error if a plugin being run does not have the same version as what was in the cache file, suggesting `plugin add` be run again, but I haven't done that at this point. It is optional, and it requires the plugin author to make some code changes if they want to provide it, since I can't automatically determine the version of the calling crate or anything tricky like that to do it. Example: ``` > plugin list | select name version is_running pid ╭───┬────────────────┬─────────┬────────────┬─────╮ │ # │ name │ version │ is_running │ pid │ ├───┼────────────────┼─────────┼────────────┼─────┤ │ 0 │ example │ 0.93.1 │ false │ │ │ 1 │ gstat │ 0.93.1 │ false │ │ │ 2 │ inc │ 0.93.1 │ false │ │ │ 3 │ python_example │ 0.1.0 │ false │ │ ╰───┴────────────────┴─────────┴────────────┴─────╯ ``` cc @maxim-uvarov (he asked for it) # User-Facing Changes - `plugin list` gets a `version` column - `version` shows plugin versions when available - plugin authors *should* add `fn metadata()` to their `impl Plugin`, but don't have to # Tests + Formatting Tested the low level stuff and also the `plugin list` column. # After Submitting - [ ] update plugin guide docs - [ ] update plugin protocol docs (`Metadata` call & response) - [ ] update plugin template (`fn metadata()` should be easy) - [ ] release notes
This commit is contained in:
@ -18,6 +18,13 @@ fn example_plugin_path() -> PathBuf {
|
||||
.expect("nu_plugin_example not found")
|
||||
}
|
||||
|
||||
fn valid_plugin_item_data() -> PluginRegistryItemData {
|
||||
PluginRegistryItemData::Valid {
|
||||
metadata: Default::default(),
|
||||
commands: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plugin_add_then_restart_nu() {
|
||||
let result = nu_with_plugins!(
|
||||
@ -149,7 +156,7 @@ fn plugin_rm_then_restart_nu() {
|
||||
name: "example".into(),
|
||||
filename: example_plugin_path,
|
||||
shell: None,
|
||||
data: PluginRegistryItemData::Valid { commands: vec![] },
|
||||
data: valid_plugin_item_data(),
|
||||
});
|
||||
|
||||
contents.upsert_plugin(PluginRegistryItem {
|
||||
@ -157,7 +164,7 @@ fn plugin_rm_then_restart_nu() {
|
||||
// this doesn't exist, but it should be ok
|
||||
filename: dirs.test().join("nu_plugin_foo"),
|
||||
shell: None,
|
||||
data: PluginRegistryItemData::Valid { commands: vec![] },
|
||||
data: valid_plugin_item_data(),
|
||||
});
|
||||
|
||||
contents
|
||||
@ -225,7 +232,7 @@ fn plugin_rm_from_custom_path() {
|
||||
name: "example".into(),
|
||||
filename: example_plugin_path,
|
||||
shell: None,
|
||||
data: PluginRegistryItemData::Valid { commands: vec![] },
|
||||
data: valid_plugin_item_data(),
|
||||
});
|
||||
|
||||
contents.upsert_plugin(PluginRegistryItem {
|
||||
@ -233,7 +240,7 @@ fn plugin_rm_from_custom_path() {
|
||||
// this doesn't exist, but it should be ok
|
||||
filename: dirs.test().join("nu_plugin_foo"),
|
||||
shell: None,
|
||||
data: PluginRegistryItemData::Valid { commands: vec![] },
|
||||
data: valid_plugin_item_data(),
|
||||
});
|
||||
|
||||
contents
|
||||
@ -273,7 +280,7 @@ fn plugin_rm_using_filename() {
|
||||
name: "example".into(),
|
||||
filename: example_plugin_path.clone(),
|
||||
shell: None,
|
||||
data: PluginRegistryItemData::Valid { commands: vec![] },
|
||||
data: valid_plugin_item_data(),
|
||||
});
|
||||
|
||||
contents.upsert_plugin(PluginRegistryItem {
|
||||
@ -281,7 +288,7 @@ fn plugin_rm_using_filename() {
|
||||
// this doesn't exist, but it should be ok
|
||||
filename: dirs.test().join("nu_plugin_foo"),
|
||||
shell: None,
|
||||
data: PluginRegistryItemData::Valid { commands: vec![] },
|
||||
data: valid_plugin_item_data(),
|
||||
});
|
||||
|
||||
contents
|
||||
@ -331,7 +338,7 @@ fn warning_on_invalid_plugin_item() {
|
||||
name: "example".into(),
|
||||
filename: example_plugin_path,
|
||||
shell: None,
|
||||
data: PluginRegistryItemData::Valid { commands: vec![] },
|
||||
data: valid_plugin_item_data(),
|
||||
});
|
||||
|
||||
contents.upsert_plugin(PluginRegistryItem {
|
||||
|
Reference in New Issue
Block a user