Skip to content

Commit 92ec0a6

Browse files
authored
Improvements around forc plugins command (#1969)
Use the full path of the plugin when parsing it for a description. This avoids the following panic caused by trying to exec an executable in a sub-folder with a partial path: ``` ~/dev/sway/target/debug$ forc plugins Installed Plugins: thread 'main' panicked at 'Could not get plugin description.: Os { code: 2, kind: NotFound, message: "No such file or directory" }', forc/src/cli/commands/plugins.rs:43:10 stack backtrace: 0: rust_begin_unwind at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5 1: core::panicking::panic_fmt at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14 2: core::result::unwrap_failed at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1785:5 3: core::result::Result<T,E>::expect at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/result.rs:1035:23 4: forc::cli::commands::plugins::parse_description_for_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:40:16 5: forc::cli::commands::plugins::format_print_description at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:81:23 6: forc::cli::commands::plugins::print_plugin at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:97:5 7: forc::cli::commands::plugins::exec at /home/joao/dev/sway/forc/src/cli/commands/plugins.rs:28:21 ```
1 parent 753639c commit 92ec0a6

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

forc/src/cli/commands/plugins.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::cli::PluginsCommand;
22
use anyhow::{anyhow, Result};
33
use clap::Parser;
4-
use std::path::PathBuf;
4+
use std::path::{Path, PathBuf};
55
use tracing::info;
66

77
/// Find all forc plugins available via `PATH`.
@@ -32,9 +32,9 @@ pub(crate) fn exec(command: PluginsCommand) -> Result<()> {
3232

3333
/// Find a plugin's description
3434
///
35-
/// Given a plugin name, returns the description included in the `-h` opt. Returns
36-
/// a generic description if a description cannot be found
37-
fn parse_description_for_plugin(plugin: &str) -> String {
35+
/// Given a cannonical plugin path, returns the description included in the `-h` opt.
36+
/// Returns a generic description if a description cannot be found
37+
fn parse_description_for_plugin(plugin: &Path) -> String {
3838
use std::process::Command;
3939
let default_description = "No description found for this plugin.";
4040
let proc = Command::new(plugin)
@@ -78,7 +78,7 @@ fn format_print_description(
7878
.to_string()
7979
};
8080

81-
let description = parse_description_for_plugin(&display);
81+
let description = parse_description_for_plugin(&path);
8282

8383
if describe {
8484
Ok(format!(" {} \t\t{}", display, description))

0 commit comments

Comments
 (0)