Add hello.rs Hello World example
This commit is contained in:
parent
d2ef322761
commit
7d9e3d63b7
49
examples/hello.rs
Normal file
49
examples/hello.rs
Normal file
|
@ -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<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 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(())
|
||||||
|
}
|
|
@ -92,6 +92,20 @@ impl CommandStatus {
|
||||||
Self::Skipped(_c) => true,
|
Self::Skipped(_c) => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn stdout(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Self::Done(ret) => Some(ret.stdout.to_string()),
|
||||||
|
Self::Skipped(_c) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn stderr(&self) -> Option<String> {
|
||||||
|
match self {
|
||||||
|
Self::Done(ret) => Some(ret.stdout.to_string()),
|
||||||
|
Self::Skipped(_c) => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return of a Command that was effectively run
|
/// Return of a Command that was effectively run
|
||||||
|
|
Loading…
Reference in New Issue
Block a user