From beb2820874c5405f0a1835b6db757deeb12f1d0e Mon Sep 17 00:00:00 2001 From: Ross MacArthur Date: Sun, 26 Nov 2023 14:56:48 +0200 Subject: [PATCH] Support multiple item arguments --- src/lib.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c5b2ba2..40e8af1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -52,6 +52,16 @@ fn is_default(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), +} + /// A keyboard modifier key. #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize)] pub enum Key { @@ -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, + arg: Option, /// The icon displayed in the result row. #[serde(skip_serializing_if = "Option::is_none")] @@ -382,7 +392,21 @@ impl Item { /// has selected. #[must_use] pub fn arg(mut self, arg: impl Into) -> 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(mut self, args: impl IntoIterator>) -> Self + where + I: IntoIterator, + J: Into, + { + self.arg = Some(Arg::Many(args.into_iter().map(Into::into).collect())); self }