Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 14 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ url = "2.5.0"

nu-cli = "0.116.0"
nu-cmd-lang = "0.116.0"
nu-cmd-plugin = "0.116.0"
nu-cmd-extra = "0.116.0"
nu-command = { version = "0.116.0", features = ["sqlite"] }
nu-engine = "0.116.0"
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,14 @@ $ http-nu --plugin ~/.cargo/bin/nu_plugin_inc eval -c '1 | inc'
2
```

Nushell's plugin management commands (`plugin list`, `plugin stop`,
`plugin use`, `plugin add`, `plugin rm`) are available. `plugin list --engine`
shows the plugins loaded with `--plugin`, including the process id when running:

```bash
$ http-nu --plugin ~/.cargo/bin/nu_plugin_inc eval -c 'plugin list --engine | select name status pid'
```

### Module Paths

Make module paths available with `-I` / `--include-path`:
Expand Down
1 change: 1 addition & 0 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ impl Engine {
engine_state = add_shell_command_context(engine_state);
engine_state = add_cli_context(engine_state);
engine_state = nu_cmd_extra::extra::add_extra_command_context(engine_state);
engine_state = nu_cmd_plugin::add_plugin_command_context(engine_state);

load_http_nu_stdlib(&mut engine_state)?;
nu_std::load_standard_library(&mut engine_state)?;
Expand Down
16 changes: 16 additions & 0 deletions tests/eval_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,22 @@ fn test_eval_with_plugin() {
.stdout("PLUGIN_WORKS\n");
}

#[test]
fn test_eval_plugin_stop_respawns() {
let plugin_path = workspace_bin("nu_plugin_test");
Command::new(assert_cmd::cargo::cargo_bin!("http-nu"))
.args([
"eval",
"--plugin",
plugin_path.to_str().unwrap(),
"-c",
"let a = test-plugin-pid; plugin stop test; let b = test-plugin-pid; [($a != $b) ($b == (plugin list --engine | get pid.0))] | to nuon",
])
.assert()
.success()
.stdout("[true, true]\n");
}

#[test]
fn test_eval_include_path() {
let dir = TempDir::new().unwrap();
Expand Down
26 changes: 26 additions & 0 deletions tests/server_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,32 @@ async fn test_plugin_process_shared_across_requests() {
);
}

/// Tests that `plugin list --engine` is available to served scripts and reports
/// the running plugin's pid, matching the pid the plugin reports for itself.
#[tokio::test]
async fn test_plugin_list_engine() {
let plugin_path = workspace_bin("nu_plugin_test");
let server = TestServer::new_with_plugins(
"127.0.0.1:0",
r#"{|req|
let own = test-plugin-pid
let listed = plugin list --engine | where name == test | get pid.0
{own: $own, listed: $listed, status: (plugin list --engine | get status.0)} | to json -r
}"#,
false,
&[plugin_path],
)
.await;

let output = server.curl("/").await;
assert!(output.status.success());
let stdout = String::from_utf8_lossy(&output.stdout);
let v: serde_json::Value = serde_json::from_str(stdout.trim()).expect("json response");
assert_eq!(v["status"], "running");
assert!(v["own"].as_i64().is_some(), "missing plugin pid: {v}");
assert_eq!(v["own"], v["listed"]);
}

// ============================================================================
// Watch mode tests (-w/--watch)
// ============================================================================
Expand Down
Loading