Cleanup prompt macros

This commit is contained in:
Jeremy Soller
2017-01-09 14:46:21 -07:00
parent f666d06485
commit 961983e788
2 changed files with 8 additions and 12 deletions
+5 -1
View File
@@ -3,7 +3,7 @@
# General settings
[general]
# Prompt if settings are not defined
prompt = true
prompt = false
# Package settings
[packages]
@@ -11,7 +11,11 @@ orbutils = {}
# User settings
[users.root]
password = "$argon2i$m=4096,t=10,p=1$Tnc4UVV0N00$ML9LIOujd3nmAfkAwEcSTMPqakWUF0OUiLWrIy0nGLk"
uid = 0
gid = 0
name = "root"
home = "/root"
[users.user]
password = ""
+3 -11
View File
@@ -63,14 +63,6 @@ pub fn install(config: Config) -> Result<(), String> {
let mut context = liner::Context::new();
macro_rules! prompt {
($dst:expr, $($arg:tt)*) => (if config.general.prompt {
unwrap_or_prompt($dst, &mut context, &format!($($arg)*))
} else {
Ok($dst.unwrap_or_default())
})
}
macro_rules! prompt_default {
($dst:expr, $def:expr, $($arg:tt)*) => (if config.general.prompt {
match unwrap_or_prompt($dst, &mut context, &format!($($arg)*)) {
Ok(res) => if res.is_empty() {
@@ -105,9 +97,9 @@ pub fn install(config: Config) -> Result<(), String> {
let gid = user.gid.unwrap_or(uid);
let name = prompt_default!(user.name, username.clone(), "{}: name: ", username)?;
let home = prompt_default!(user.home, format!("/home/{}", username), "{}: home: ", username)?;
let shell = prompt_default!(user.shell, "/bin/ion".to_string(), "{}: shell: ", username)?;
let name = prompt!(user.name, username.clone(), "{}: name [{}]: ", username, username)?;
let home = prompt!(user.home, format!("/home/{}", username), "{}: home [/home/{}]: ", username, username)?;
let shell = prompt!(user.shell, "/bin/ion".to_string(), "{}: shell [/bin/ion]: ", username)?;
println!("Creating user {}:", username);
println!("\tPassword: {}", password);