diff --git a/examples/hello.rs b/examples/hello.rs new file mode 100644 index 0000000..f9af60c --- /dev/null +++ b/examples/hello.rs @@ -0,0 +1,49 @@ +use rustible::Facts; + +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 for PlaybookError { + fn from(e: CommandError) -> PlaybookError { + PlaybookError::Command(e) + } +} + +impl From for PlaybookError { + fn from(e: PackageError) -> PlaybookError { + PlaybookError::Package(e) + } +} + +fn main() -> Result<(), PlaybookError> { + let facts = Facts::new(); + println!("rustible running system: {}", facts.os.family().as_str()); + + 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(()) +} diff --git a/src/modules/command/mod.rs b/src/modules/command/mod.rs index d36cc92..22c314b 100644 --- a/src/modules/command/mod.rs +++ b/src/modules/command/mod.rs @@ -92,6 +92,20 @@ impl CommandStatus { Self::Skipped(_c) => true, } } + + pub fn stdout(&self) -> Option { + match self { + Self::Done(ret) => Some(ret.stdout.to_string()), + Self::Skipped(_c) => None, + } + } + + pub fn stderr(&self) -> Option { + match self { + Self::Done(ret) => Some(ret.stdout.to_string()), + Self::Skipped(_c) => None, + } + } } /// Return of a Command that was effectively run