summaryrefslogtreecommitdiffstats
path: root/src/poem/elements/verse.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/poem/elements/verse.rs')
-rw-r--r--src/poem/elements/verse.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/poem/elements/verse.rs b/src/poem/elements/verse.rs
index 9ebd31d..4d5f31c 100644
--- a/src/poem/elements/verse.rs
+++ b/src/poem/elements/verse.rs
@@ -23,6 +23,9 @@ use std::sync::{Arc, Mutex};
/// input on `STDIN` from the previous [Verse].
#[derive(Debug, Clone)]
pub struct Verse {
+ /// Environment variables to fork with
+ pub notes: Stanza,
+
/// A command and its arguments (also see [Stanza])
pub stanza: Stanza,
@@ -119,6 +122,7 @@ impl Verse {
/// [Rune::None], and `couplet` set to 0.
pub fn new() -> Self {
Verse {
+ notes: Stanza::new(),
stanza: Stanza::new(),
couplet: 0,
io: Vec::new(),
@@ -148,6 +152,20 @@ impl Verse {
}
}
+ /// Set the [Verse]'s command's environment
+ ///
+ /// Use self.notate to set inline environment variables
+ pub fn notate(&self, command: &mut Command) {
+ for var in self.notes.clone() {
+ let split: Vec<&str> = var.split("=").collect();
+ if split.len() == 1 {
+ command.env(split[0], "");
+ } else {
+ command.env(split[0], split[1]);
+ }
+ }
+ }
+
/// Alias to [Verse].stanza.push()
pub fn push(&mut self, word: String) {
self.stanza.push(word);
@@ -202,6 +220,7 @@ impl Verse {
// Push the word
match channel {
+ Some(Rune::Notes) => self.notes.push(word.iter().collect()),
Some(Rune::Read) => self.ip.push(word.iter().collect()),
Some(Rune::Write) | Some(Rune::Addendum) => self.op.push(word.iter().collect()),
Some(Rune::Write2) | Some(Rune::Addendum2) => self.ep.push(word.iter().collect()),
@@ -334,6 +353,7 @@ impl Verse {
}
_ => {
let mut command = Command::new(self.verb());
+ self.notate(&mut command);
incant!(self.verb(), command, out, pids, env, self)
}
}