runtasktic 1.2.1

Command-line task management tool for execution of regular long sequential or parallel tasks.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
pub use self::task::Task;
use anyhow::Result;
use std::collections::HashMap;

mod de;
mod task;

#[derive(Debug, PartialEq, Clone, Default, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct Config {
  #[serde(default, deserialize_with = "self::de::deserialize_task")]
  pub tasks: HashMap<String, Task>,
  #[serde(default = "self::de::default_concurrency")]
  pub concurrency: i64,
  pub notification: Option<Notification>,
  pub working_dir: Option<String>,
  pub stdout: Option<String>,
  pub stderr: Option<String>,
  #[serde(default)]
  pub on_failure: OnFailure,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct Notification {
  pub slack: Option<Slack>,
  pub discord: Option<Discord>,
  pub print: Option<Print>,
  #[serde(rename = "email")]
  pub mail: Option<Mail>,
  #[serde(default)]
  pub when: WhenNotify,
  #[serde(default)]
  pub messages: Messages,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct Slack {
  #[serde(deserialize_with = "self::de::notification_slack_url")]
  pub url: String,
  #[serde(deserialize_with = "self::de::notification_slack_channel")]
  pub channel: String,
  pub emoji: Option<String>,
  #[serde(default, deserialize_with = "self::de::notification_slack_username")]
  pub username: Option<String>,
  pub when: Option<WhenNotify>,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct Discord {
  #[serde(deserialize_with = "self::de::notification_discord_url")]
  pub url: String,
  #[serde(default, deserialize_with = "self::de::notification_discord_username")]
  pub username: Option<String>,
  pub when: Option<WhenNotify>,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct Print {
  pub output: String,
  pub when: Option<WhenNotify>,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct Mail {
  pub from: MailAddress,
  pub to: MailAddress,
  #[serde(default = "self::de::default_email_subject")]
  pub subject: String,
  pub smtp: MailSMTP,
  pub when: Option<WhenNotify>,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case", untagged)]
pub enum MailAddress {
  A(String),
  NA {
    name: Option<String>,
    address: String,
  },
  V(Vec<MailAddress>),
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct MailSMTP {
  #[serde(deserialize_with = "self::de::notification_email_smtp_hostname")]
  pub hostname: String,
  #[serde(default = "self::de::default_email_port")]
  pub port: u16,
  #[serde(
    default,
    deserialize_with = "self::de::notification_email_smtp_username"
  )]
  pub username: Option<String>,
  #[serde(deserialize_with = "self::de::notification_email_smtp_secret")]
  pub secret: String,
  #[serde(default = "self::de::default_true")]
  pub tls: bool,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum WhenNotify {
  Always,
  TaskEnd,
  End,
  Never,
  Fail,
}

#[derive(Debug, PartialEq, Clone, Copy, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum OnFailure {
  Continue,
  Exit,
}

#[derive(Debug, PartialEq, Clone, serde::Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct Messages {
  pub task_end: String,
  pub all_tasks_end: String,
  pub task_failed: String,
}

impl Config {
  pub fn from_str(s: &str) -> Result<Config> {
    Ok(serde_yaml::from_str(s)?)
  }

  pub fn tasks(&self) -> &HashMap<String, Task> {
    &self.tasks
  }

  pub fn tasks_values_mut(&'_ mut self) -> std::collections::hash_map::ValuesMut<'_, String, Task> {
    self.tasks.values_mut()
  }
}

impl Notification {
  pub async fn notify_task_end(&self, task: &Task, status_code: std::process::ExitStatus) {
    let success = Some(status_code.success());
    if !self.when.should_notify(&WhenNotify::TaskEnd, success) {
      return;
    }

    let short_cmd = task.short_command();
    let id = task.label();
    let msg = crate::notification::replace_templates(&self.messages.task_end);
    let msg = msg.replace("{task.id}", &id);
    let msg = msg.replace("{task.full_cmd}", &task.full_command());
    let msg = msg.replace("{task.short_cmd}", &short_cmd);
    let msg = msg.replace("{task.status_code}", &format!("{}", status_code));

    if let Some(print) = self.print.notify(&WhenNotify::TaskEnd, success) {
      if let Err(e) = crate::notification::notification_print(&print, msg.as_str()) {
        eprintln!("Can't use print notification: {}", e);
      }
    }

    if let Some(slack) = self.slack.notify(&WhenNotify::TaskEnd, success) {
      if let Err(e) = crate::notification::post_slack(&slack, msg.as_str()) {
        eprintln!("Can't use slack notification: {}", e);
      }
    }

    if let Some(discord) = self.discord.notify(&WhenNotify::TaskEnd, success) {
      if let Err(e) = crate::notification::post_discord(&discord, msg.as_str()) {
        eprintln!("Can't use discord notification: {}", e);
      }
    }

    if let Some(email) = self.mail.notify(&WhenNotify::TaskEnd, success) {
      if let Err(e) = crate::notification::notification_email(&email, msg.as_str()).await {
        eprintln!("Can't use email notification: {}", e);
      }
    };
  }

  pub async fn notify_all_tasks_end(&self, success: i32, failures: i32, failed: bool) {
    let has_failure = Some(failures > 0);
    if !self.when.should_notify(&WhenNotify::End, has_failure) {
      return;
    }
    let msg = if !failed {
      &self.messages.all_tasks_end
    } else {
      &self.messages.task_failed
    };
    let msg = crate::notification::replace_templates(msg);
    let msg = msg.replace("{resume.success}", &format!("{}", success));
    let msg = msg.replace("{resume.failures}", &format!("{}", failures));

    if let Some(print) = self.print.notify(&WhenNotify::End, has_failure) {
      if let Err(e) = crate::notification::notification_print(&print, msg.as_str()) {
        eprintln!("Can't use print notification: {}", e);
      }
    }

    if let Some(slack) = self.slack.notify(&WhenNotify::End, has_failure) {
      if let Err(e) = crate::notification::post_slack(&slack, msg.as_str()) {
        eprintln!("Can't use slack notification: {}", e);
      }
    }

    if let Some(discord) = self.discord.notify(&WhenNotify::End, has_failure) {
      if let Err(e) = crate::notification::post_discord(&discord, msg.as_str()) {
        eprintln!("Can't use discord notification: {}", e);
      }
    }

    if let Some(email) = self.mail.notify(&WhenNotify::End, has_failure) {
      if let Err(e) = crate::notification::notification_email(&email, msg.as_str()).await {
        eprintln!("Can't use email notification: {}", e);
      }
    };
  }
}

impl Mail {
  pub fn smtp_hostname(&self) -> &String {
    &self.smtp.hostname
  }

  pub fn smtp_port(&self) -> u16 {
    self.smtp.port
  }

  pub fn smtp_username(&self) -> &String {
    match &self.smtp.username {
      Some(username) => username,
      None => self.from.email(),
    }
  }

  pub fn smtp_secret(&self) -> &String {
    &self.smtp.secret
  }

  pub fn smtp_tls(&self) -> bool {
    self.smtp.tls
  }
}

impl Default for OnFailure {
  fn default() -> OnFailure {
    OnFailure::Continue
  }
}

impl WhenNotify {
  pub fn should_notify(&self, when: &WhenNotify, success: Option<bool>) -> bool {
    self != &WhenNotify::Never
      && (self == &WhenNotify::Always
        || self == when
        || (Some(false) == success && self == &WhenNotify::Fail))
  }
}

trait When {
  fn when(&self) -> &Option<WhenNotify>;
}

impl When for Print {
  fn when(&self) -> &Option<WhenNotify> {
    &self.when
  }
}

impl When for Slack {
  fn when(&self) -> &Option<WhenNotify> {
    &self.when
  }
}
impl When for Discord {
  fn when(&self) -> &Option<WhenNotify> {
    &self.when
  }
}

impl When for Mail {
  fn when(&self) -> &Option<WhenNotify> {
    &self.when
  }
}

trait Notify {
  fn notify(&self, when: &WhenNotify, success: Option<bool>) -> Self;
}

impl<T: Clone + When> Notify for Option<T> {
  fn notify(&self, state: &WhenNotify, success: Option<bool>) -> Self {
    if let Some(it) = self {
      if let Some(when) = it.when() {
        if !when.should_notify(state, success) {
          return None;
        }
      }
      return Some(it.clone());
    }
    None
  }
}

impl Default for Messages {
  fn default() -> Self {
    Self {
      task_end: String::from("Task {task.id} ended with status code {task.status_code}"),
      all_tasks_end: String::from(
        "All tasks ended. Got {resume.success} success and {resume.failures} failure.",
      ),
      task_failed: String::from(
        "Tasks ended prematurely. Got {resume.success} success and {resume.failures} failure. Contains one critical failure.",
      ),
    }
  }
}

impl Default for WhenNotify {
  fn default() -> Self {
    Self::End
  }
}

impl Into<(String, String)> for MailAddress {
  fn into(self) -> (String, String) {
    match self {
      MailAddress::A(a) => ("".into(), a.into()),
      MailAddress::NA { name, address } => (name.unwrap_or("".into()), address.into()),
      MailAddress::V(v) => v.first().map(|e| e.clone().into()).unwrap(),
    }
  }
}

impl Into<Vec<(String, String)>> for MailAddress {
  fn into(self) -> Vec<(String, String)> {
    match &self {
      MailAddress::A(a) => vec![("".into(), a.into())],
      MailAddress::NA { name, address } => {
        vec![(name.clone().unwrap_or("".into()), address.into())]
      }
      MailAddress::V(v) => v.into_iter().map(|e| e.clone().into()).collect(),
    }
  }
}

impl MailAddress {
  fn email(&self) -> &String {
    match self {
      Self::A(email) => email,
      Self::NA { name: _, address } => address,
      Self::V(addresses) => addresses.first().unwrap().email(),
    }
  }
}

#[cfg(test)]
mod test {
  use super::*;
  use std::fs;

  const SAMPLE_YAML: &str = "tests/resources/sample.yml";
  const NOTIFICATION_YAML: &str = "tests/resources/notification.yml";
  const CONCURRENCY_YAML: &str = "tests/resources/concurrency.yml";
  const ON_FAILURE_YAML: &str = "tests/resources/on_failure.yml";

  #[test]
  pub fn get_no_tasks() -> anyhow::Result<()> {
    let config: Config = serde_yaml::from_str(
      "
    notifications:
      slack: none
    ",
    )?;

    assert_eq!(config.notification, None);
    assert_eq!(config.tasks, HashMap::new());
    Ok(())
  }

  #[test]
  pub fn get_tasks_single_empty_task() -> anyhow::Result<()> {
    let config: Config = serde_yaml::from_str(
      "
    tasks:
      a:
    ",
    )?;
    let mut expected: HashMap<String, Task> = HashMap::new();
    expected.insert(
      String::from("a"),
      Task::new(String::from("a"), vec![], vec![], None),
    );
    assert_eq!(config.tasks, expected);
    Ok(())
  }

  #[test]
  pub fn get_tasks_single_command_task() -> anyhow::Result<()> {
    let config: Config = serde_yaml::from_str(
      "
    tasks:
      a:
        commands:
        - echo OK
    ",
    )?;
    let mut expected: HashMap<String, Task> = HashMap::new();
    expected.insert(
      String::from("a"),
      Task::new(
        String::from("a"),
        vec![String::from("echo OK")],
        vec![],
        None,
      ),
    );

    assert_eq!(config.tasks, expected);
    Ok(())
  }

  #[test]
  pub fn get_tasks_single_command_depends_on_task() -> anyhow::Result<()> {
    let config: Config = serde_yaml::from_str(
      "
    tasks:
      a:
        commands:
        - echo OK
        depends_on:
        - b
    ",
    )?;

    let mut expected: HashMap<String, Task> = HashMap::new();
    expected.insert(
      String::from("a"),
      Task::new(
        String::from("a"),
        vec![String::from("echo OK")],
        vec![String::from("b")],
        None,
      ),
    );

    assert_eq!(config.tasks, expected);
    Ok(())
  }

  #[test]
  pub fn get_email_notifiaction_default_values() -> anyhow::Result<()> {
    let notification: Notification = serde_yaml::from_str(
      "
    email:
      from: sender@example.com
      to: receiver@example.com
      smtp:
        hostname: smtp.example.com
        secret: secret-password
    ",
    )?;
    let expected_smtp = MailSMTP {
      hostname: "smtp.example.com".to_string(),
      port: 587,
      username: None,
      secret: "secret-password".to_string(),
      tls: true,
    };
    let expected_mail = Mail {
      from: MailAddress::A("sender@example.com".to_string()),
      to: MailAddress::A("receiver@example.com".to_string()),
      subject: super::de::default_email_subject(),
      smtp: expected_smtp,
      when: None,
    };
    let email = notification.mail;

    assert!(email.is_some());
    assert_eq!(email.clone(), Some(expected_mail));
    assert_eq!(
      email.clone().unwrap().smtp_username(),
      &"sender@example.com".to_string()
    );
    Ok(())
  }

  #[test]
  fn sample_yaml() {
    let yaml = fs::read_to_string(SAMPLE_YAML).unwrap();
    let config = Config::from_str(yaml.as_str()).unwrap();

    let a = Task::new("a".to_string(), vec![echo("a"), sleep("0.5")], vec![], None);
    let b = Task::new("b", vec![echo("b"), sleep("0.5")], vs(&["a"]), None);
    let c = Task::new("c", vec![echo("c")], vs(&["a"]), None);
    let d = Task::new("d", vec![echo("d")], vs(&["b", "c"]), None);

    assert_eq!(config.notification, None);
    assert_eq!(config.concurrency, -1);
    assert_eq!(config.working_dir, Some(String::from("/custom/directory")));
    assert_eq!(config.stdout, Some(String::from("none")));
    assert_eq!(config.stderr, Some(String::from("none")));
    assert_eq!(config.tasks.len(), 4);
    assert_eq!(config.tasks.get(&"a".to_string()), Some(&a));
    assert_eq!(config.tasks.get(&"b".to_string()), Some(&b));
    assert_eq!(config.tasks.get(&"c".to_string()), Some(&c));
    assert_eq!(config.tasks.get(&"d".to_string()), Some(&d));
  }

  #[test]
  fn concurrency_yaml() {
    let yaml = fs::read_to_string(CONCURRENCY_YAML).unwrap();
    let config = Config::from_str(yaml.as_str()).unwrap();

    let a1 = Task::new(
      "a1",
      vec![echo("Begin a1"), sleep("0.5"), echo("End a1")],
      vec![],
      None,
    );
    let a2 = Task::new(
      "a2",
      vec![echo("Begin a2"), sleep("1"), echo("End a2")],
      vec![],
      None,
    );
    let b = Task::new(
      "b",
      vec![echo("Begin b"), sleep("0.5"), echo("End b")],
      vs(&["a1", "a2"]),
      None,
    );
    let c = Task::new(
      "c",
      vec![echo("Begin c"), sleep("1"), echo("End c")],
      vs(&["a1"]),
      None,
    );
    let d = Task::new(
      "d",
      vec![echo("Begin d"), sleep("0.5"), echo("End d")],
      vs(&["a1"]),
      None,
    );
    let e = Task::new(
      "e",
      vec![echo("Begin e"), sleep("0.5"), echo("End e")],
      vs(&["b", "c", "d"]),
      None,
    );
    let f = Task::new(
      "f",
      vec![echo("Begin f"), sleep("1"), echo("End f")],
      vs(&["c"]),
      None,
    );

    assert_eq!(config.notification, None);
    assert_eq!(config.concurrency, 2);
    assert_eq!(config.tasks.len(), 7);
    assert_eq!(config.tasks.get(&"a1".to_string()), Some(&a1));
    assert_eq!(config.tasks.get(&"a2".to_string()), Some(&a2));
    assert_eq!(config.tasks.get(&"b".to_string()), Some(&b));
    assert_eq!(config.tasks.get(&"c".to_string()), Some(&c));
    assert_eq!(config.tasks.get(&"d".to_string()), Some(&d));
    assert_eq!(config.tasks.get(&"e".to_string()), Some(&e));
    assert_eq!(config.tasks.get(&"f".to_string()), Some(&f));
  }

  #[test]
  fn notification_yaml() {
    let yaml = fs::read_to_string(NOTIFICATION_YAML).unwrap();
    let config = Config::from_str(yaml.as_str()).unwrap();

    let a = Task::new(
      "a",
      vec![echo("Begin a"), sleep("0.5"), echo("End a")],
      vec![],
      None,
    );
    let b = Task::new(
      "b",
      vec![echo("Begin b"), sleep("0.5"), echo("End b")],
      vs(&["a"]),
      None,
    );
    let c = Task::new(
      "c",
      vec![echo("Begin c"), sleep("1"), echo("End c")],
      vs(&["a"]),
      None,
    );
    let d = Task::new(
      "d",
      vec![echo("Begin d"), sleep("0.5"), echo("End d")],
      vs(&["a"]),
      None,
    );
    let e = Task::new(
      "e",
      vec![echo("Begin e"), sleep("0.5"), echo("End e")],
      vs(&["b", "c", "d"]),
      None,
    );

    let slack = Slack {
      url: "https://hooks.slack.com/services/XXXXX/XXXXX/XXXXX".to_string(),
      channel: "#channel".to_string(),
      username: Some("runtasktic".to_string()),
      emoji: Some(":rocket:".to_string()),
      when: None,
    };
    let discord = Discord {
      url: "https://discord.com/api/webhooks/XXXXX/XXXXX".to_string(),
      username: Some("runtasktic".to_string()),
      when: None,
    };
    let print = Print {
      output: "stderr".to_string(),
      when: None,
    };
    let email = Mail {
      from: MailAddress::NA {
        name: Some("Sender Name".to_string()),
        address: "sender@example.com".to_string(),
      },
      to: MailAddress::V(vec![MailAddress::NA {
        name: Some("Receiver Name".to_string()),
        address: "receiver@example.com".to_string(),
      }]),
      subject: "Subject".to_string(),
      smtp: MailSMTP {
        hostname: "smtp.example.com".to_string(),
        port: 1587,
        username: Some("sender@example.com".to_string()),
        secret: "secret-password".to_string(),
        tls: false,
      },
      when: None,
    };
    let notification = Notification {
      slack: Some(slack),
      discord: Some(discord),
      print: Some(print),
      mail: Some(email),
      when: WhenNotify::Always,
      messages: Messages::default(),
    };

    assert_eq!(config.notification, Some(notification));
    assert_eq!(config.concurrency, -1);
    assert_eq!(config.tasks.len(), 5);
    assert_eq!(config.tasks.get(&"a".to_string()), Some(&a));
    assert_eq!(config.tasks.get(&"b".to_string()), Some(&b));
    assert_eq!(config.tasks.get(&"c".to_string()), Some(&c));
    assert_eq!(config.tasks.get(&"d".to_string()), Some(&d));
    assert_eq!(config.tasks.get(&"e".to_string()), Some(&e));
  }

  #[test]
  fn on_failure_yaml() {
    let yaml = fs::read_to_string(ON_FAILURE_YAML).unwrap();
    let config = Config::from_str(yaml.as_str()).unwrap();

    let a = Task::new(
      "a",
      vec![echo("Begin a"), format!("unknown-cmd"), echo("End a")],
      vec![],
      Some(OnFailure::Continue),
    );
    let b = Task::new(
      "b",
      vec![echo("Begin b"), format!("unknown-cmd"), echo("End b")],
      vs(&["a"]),
      Some(OnFailure::Exit),
    );
    let c = Task::new(
      "c",
      vec![echo("Begin c"), sleep("1"), echo("End c")],
      vs(&["a"]),
      None,
    );
    let d = Task::new(
      "d",
      vec![echo("Begin d"), sleep("0.5"), echo("End d")],
      vs(&["a"]),
      None,
    );
    let e = Task::new(
      "e",
      vec![echo("Begin e"), sleep("0.5"), echo("End e")],
      vs(&["b", "c", "d"]),
      None,
    );

    assert_eq!(config.on_failure, OnFailure::Continue);
    assert_eq!(config.notification, None);
    assert_eq!(config.concurrency, 2);
    assert_eq!(config.tasks.len(), 5);
    assert_eq!(config.tasks.get(&"a".to_string()), Some(&a));
    assert_eq!(config.tasks.get(&"b".to_string()), Some(&b));
    assert_eq!(config.tasks.get(&"c".to_string()), Some(&c));
    assert_eq!(config.tasks.get(&"d".to_string()), Some(&d));
    assert_eq!(config.tasks.get(&"e".to_string()), Some(&e));
  }

  fn echo(msg: &str) -> String {
    format!("echo {}", msg)
  }

  fn sleep(time: &str) -> String {
    format!("sleep {}", time)
  }

  fn vs(vec: &[&str]) -> Vec<String> {
    vec.iter().map(|s| s.to_string()).collect()
  }
}