Command runner args, Paths and AsRef
This commit is contained in:
parent
5d5e9dfcb4
commit
3ccf64fac1
32 changed files with 696 additions and 721 deletions
|
|
@ -69,7 +69,7 @@ impl fmt::Display for UserError {
|
|||
}
|
||||
}
|
||||
|
||||
pub struct User<'a, C: 'a + CommandRunner, A: 'a + UserAdder> {
|
||||
pub struct User<'a, C: CommandRunner, A: UserAdder> {
|
||||
user_name: Cow<'a, str>,
|
||||
command_runner: &'a C,
|
||||
user_adder: &'a A,
|
||||
|
|
@ -95,7 +95,7 @@ impl<'a, C: CommandRunner, A: 'a + UserAdder> Symbol for User<'a, C, A> {
|
|||
fn target_reached(&self) -> Result<bool, Box<dyn Error>> {
|
||||
let output = self
|
||||
.command_runner
|
||||
.run_with_args("getent", &["passwd", &*self.user_name])?;
|
||||
.run_with_args("getent", args!["passwd", self.user_name.as_ref()])?;
|
||||
match output.status.code() {
|
||||
Some(2) => Ok(false),
|
||||
Some(0) => Ok(true),
|
||||
|
|
@ -106,12 +106,12 @@ impl<'a, C: CommandRunner, A: 'a + UserAdder> Symbol for User<'a, C, A> {
|
|||
fn execute(&self) -> Result<(), Box<dyn Error>> {
|
||||
self
|
||||
.user_adder
|
||||
.add_user(&*self.user_name)
|
||||
.add_user(self.user_name.as_ref())
|
||||
.map_err(|e| Box::new(e) as Box<dyn Error>)
|
||||
}
|
||||
|
||||
fn provides(&self) -> Option<Vec<Resource>> {
|
||||
Some(vec![Resource::new("user", self.user_name.to_string())])
|
||||
Some(vec![Resource::new("user", self.user_name.to_owned())])
|
||||
}
|
||||
|
||||
fn as_action<'b>(&'b self, runner: &'b dyn SymbolRunner) -> Box<dyn Action + 'b> {
|
||||
|
|
@ -140,7 +140,7 @@ impl<'a, C: CommandRunner> UserAdder for SystemUserAdder<'a, C> {
|
|||
fn add_user(&self, user_name: &str) -> Result<(), UserAdderError> {
|
||||
let output = self.command_runner.run_with_args(
|
||||
"adduser",
|
||||
&[
|
||||
args![
|
||||
// "-m", // Necessary for Fedora, not accepted in Debian
|
||||
"--system", user_name,
|
||||
],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue