Skip to content

Commit

Permalink
Support multiple item arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
rossmacarthur committed Nov 26, 2023
1 parent b4f0f8c commit beb2820
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ fn is_default<T: Default + PartialEq>(t: &T) -> bool {
// Definitions
////////////////////////////////////////////////////////////////////////////////

/// An arg, either a string or a sequence of strings.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
#[serde(untagged)]
enum Arg {
/// A single string.
One(String),
/// A sequence of strings.
Many(Vec<String>),
}

/// A keyboard modifier key.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize)]
pub enum Key {
Expand Down Expand Up @@ -155,7 +165,7 @@ pub struct Item {

/// The argument which is passed through to the output.
#[serde(skip_serializing_if = "Option::is_none")]
arg: Option<String>,
arg: Option<Arg>,

/// The icon displayed in the result row.
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -382,7 +392,21 @@ impl Item {
/// has selected.
#[must_use]
pub fn arg(mut self, arg: impl Into<String>) -> Self {
self.arg = Some(arg.into());
self.arg = Some(Arg::One(arg.into()));
self
}

/// Set the arguments which are passed through the workflow to the connected
/// output action.
///
/// Same as [`arg`], but allows you to pass multiple arguments.
#[must_use]
pub fn args<I, J>(mut self, args: impl IntoIterator<Item = impl Into<String>>) -> Self
where
I: IntoIterator<Item = J>,
J: Into<String>,
{
self.arg = Some(Arg::Many(args.into_iter().map(Into::into).collect()));
self
}

Expand Down

0 comments on commit beb2820

Please sign in to comment.