return from main function
This commit is contained in:
parent
f7fc3229ed
commit
c21ba2fa39
@ -4,9 +4,9 @@ extern crate clap;
|
||||
use clap::{App, Arg};
|
||||
|
||||
extern crate adduser;
|
||||
use adduser::api::UserDBWrite;
|
||||
use adduser::{api::UserDBWrite, UserLibError};
|
||||
|
||||
fn main() {
|
||||
fn main() -> Result<(), UserLibError> {
|
||||
env_logger::init();
|
||||
let matches = App::new("Create a new linux user")
|
||||
.version("0.1.0")
|
||||
@ -14,8 +14,6 @@ fn main() {
|
||||
.about("Create a linux user do not use this in production (yet)")
|
||||
.arg(
|
||||
Arg::new("username")
|
||||
.short('n')
|
||||
.long("username")
|
||||
.value_name("USERNAME")
|
||||
.about("the new users name")
|
||||
.takes_value(true)
|
||||
@ -54,20 +52,14 @@ fn main() {
|
||||
|
||||
let mut db = adduser::UserDBLocal::load_files(mf).unwrap();
|
||||
|
||||
let _user_res: Result<&adduser::User, adduser::UserLibError> = db.new_user(
|
||||
match db.new_user(
|
||||
adduser::api::CreateUserArgs::builder()
|
||||
.username(matches.value_of("username").unwrap())
|
||||
// .delete_home(adduser::api::DeleteHome::Delete)
|
||||
.build()
|
||||
.unwrap(),
|
||||
);
|
||||
|
||||
let user = adduser::User::default()
|
||||
.username("fest".into())
|
||||
.shell_path("/bin/mash".into())
|
||||
.clone();
|
||||
|
||||
println!("{}", user);
|
||||
|
||||
//db.new_user().expect("failed to create the user");
|
||||
) {
|
||||
Ok(_) => Ok(()),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![feature(option_expect_none)]
|
||||
#![warn(
|
||||
clippy::all,
|
||||
//clippy::restriction,
|
||||
@ -8,6 +7,7 @@
|
||||
)]
|
||||
//#![allow(clippy::non_ascii_literal)]
|
||||
#![allow(clippy::missing_errors_doc)]
|
||||
#![allow(clippy::clippy::multiple_crate_versions)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
@ -235,9 +235,10 @@ impl UserDBWrite for UserDBLocal {
|
||||
opened.expect("failed to lock files!");
|
||||
dbg!(&locked_p);
|
||||
locked_p.append(format!("{}", new_user))?;
|
||||
self.users
|
||||
assert!(self
|
||||
.users
|
||||
.insert(args.username.to_owned(), new_user)
|
||||
.expect_none("Is always none");
|
||||
.is_none());
|
||||
self.users
|
||||
.get(args.username)
|
||||
.map_or_else(|| Err("User was not successfully added!".into()), Ok)
|
||||
|
@ -52,6 +52,8 @@ fn test_create_user_binary() {
|
||||
let s = Fixture::copy("shadow");
|
||||
let g = Fixture::copy("group");
|
||||
|
||||
dbg!(&p, &s, &g);
|
||||
|
||||
let pf = fs::read_to_string(&p.path).unwrap();
|
||||
|
||||
let mf = adduser::Files {
|
||||
|
@ -5,6 +5,7 @@ use tempfile::TempDir;
|
||||
|
||||
use std::ops::Deref;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Fixture {
|
||||
pub path: PathBuf,
|
||||
pub source: PathBuf,
|
||||
|
Loading…
Reference in New Issue
Block a user