Expand description

interactive-actions is a library for automating running scripts and human interactions in a declarative way.

Actions

This crate uses a set of Actions to describe a workflow. You can give it a name, custom script to run with run, and an Interaction for interacting against a human.

You also have additional control flags such as ignore_exit, capture and others. See below:

Examples

Run a script conditionally, only after confirming:

use interactive_actions::data::{Action, ActionHook, VarBag};
use interactive_actions::ActionRunner;
use std::path::Path;

let actions_defs: Vec<Action> = serde_yaml::from_str(
r#"
- name: confirm-action
  interaction:
    kind: confirm
    prompt: are you sure?
  run: echo hello
"#).unwrap();

let mut actions = ActionRunner::default();
let mut v = VarBag::new();
// give it a current working folder `.` and a progress function
actions.run(&actions_defs, Some(Path::new(".")), &mut v, ActionHook::After, Some(|action: &Action| { println!("running: {:?}", action) }));

Describe a set of actions and interactive prompting, optionally using input variable capture, and then run everything interatively.

use interactive_actions::data::{Action, ActionHook, VarBag};
use interactive_actions::ActionRunner;
use std::path::Path;

let actions_defs: Vec<Action> = serde_yaml::from_str(
r#"
- name: confirm-action
  interaction:
    kind: confirm
    prompt: are you sure?
    out: confirm
- name: input-action
  interaction:
    kind: input
    prompt: which city?
    default: dallas
    out: city
- name: select-action
  interaction:
    kind: select
    prompt: select transport
    options:
    - bus
    - train
    - walk
    default: bus
    out: transport
  run: echo {{city}} {{transport}}
"#).unwrap();

let mut actions = ActionRunner::default();
let mut v = VarBag::new();
actions.run(&actions_defs, Some(Path::new(".")), &mut v, ActionHook::After, None::<fn(&Action) -> ()>);

Modules

Structs