45 lines
1013 B
Rust
45 lines
1013 B
Rust
use rustible::modules::{
|
|
PlaybookRun,
|
|
package::{PackageModule as Package, PackageState, PackageError},
|
|
command::{CommandModule as Command, CommandError},
|
|
};
|
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
pub enum PlaybookError {
|
|
Command(CommandError),
|
|
Package(PackageError),
|
|
}
|
|
|
|
impl From<CommandError> for PlaybookError {
|
|
fn from(e: CommandError) -> PlaybookError {
|
|
PlaybookError::Command(e)
|
|
}
|
|
}
|
|
|
|
impl From<PackageError> for PlaybookError {
|
|
fn from(e: PackageError) -> PlaybookError {
|
|
PlaybookError::Package(e)
|
|
}
|
|
}
|
|
|
|
fn main() -> Result<(), PlaybookError> {
|
|
let mut playbook = PlaybookRun::new();
|
|
|
|
let pkg = Package::new()
|
|
.name("hello")
|
|
.state(PackageState::Present)
|
|
.build();
|
|
playbook.run(pkg)?;
|
|
|
|
let cmd = Command::new()
|
|
.program("hello")
|
|
.arg("-g")
|
|
.arg("\"Welcome to rustible!\"")
|
|
.build();
|
|
|
|
let res = playbook.run(cmd)?;
|
|
println!("STDOUT:\n{}", res.stdout().unwrap());
|
|
|
|
Ok(())
|
|
}
|