pmpx_plugin/manager.rs
1//! The trait a plugin implements: the one thing a plugin author writes by hand.
2
3use std::ffi::OsString;
4
5use crate::{CommandSpec, Context, Family, PluginError, Verb};
6
7/// An implementation of one package manager backend, a purely synchronous interface: no `async`,
8/// no callbacks, no I/O -- passing a `Future` across the `dlopen` boundary is the most fragile
9/// part of this approach. It should only do mapping; see the crate docs for the constraints.
10pub trait PackageManager: Send + Sync {
11 /// Plugin name, e.g. `"cargo"`. The host compares it against the name declared in the
12 /// manifest and refuses to load on a mismatch.
13 fn name(&self) -> &str;
14
15 /// The ecosystem it belongs to.
16 fn family(&self) -> Family;
17
18 /// Translate "verb + arguments" into one concrete command.
19 /// Return [`PluginError::UnsupportedVerb`] when a verb is not supported and do not improvise a
20 /// near-equivalent command -- the host degrades `exec`, the other verbs report the error as-is,
21 /// and either is better than guessing.
22 fn command(
23 &self,
24 ctx: &Context,
25 verb: Verb,
26 args: &[OsString],
27 ) -> Result<CommandSpec, PluginError>;
28}