Skip to content

Commit

Permalink
Allow passing a username directly
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed May 2, 2023
1 parent 599d8d5 commit c002fd3
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/greeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ pub struct Greeter {

pub user_menu: bool,

pub default_user: Option<String>,
pub remember: bool,
pub remember_session: bool,
pub remember_user_session: bool,
Expand Down Expand Up @@ -125,6 +126,11 @@ impl Greeter {
}
}

if let Some(default_user) = greeter.default_user.clone() {
greeter.username = default_user;
greeter.username_mask = Some(String::from("TOTO"));
}

if greeter.remember {
if let Ok(username) = get_last_user_username() {
greeter.username = username.clone();
Expand Down Expand Up @@ -257,6 +263,7 @@ impl Greeter {
opts.optopt("g", "greeting", "show custom text above login prompt", "GREETING");
opts.optflag("t", "time", "display the current date and time");
opts.optopt("", "time-format", "custom strftime format for displaying date and time", "FORMAT");
opts.optopt("u", "user", "set the default user", "USER");
opts.optflag("r", "remember", "remember last logged-in username");
opts.optflag("", "remember-session", "remember last selected session");
opts.optflag("", "remember-user-session", "remember last selected session for each user");
Expand Down Expand Up @@ -349,6 +356,7 @@ impl Greeter {
process::exit(1);
}

self.default_user = self.option("user");
self.remember = self.config().opt_present("remember");
self.remember_session = self.config().opt_present("remember-session");
self.remember_user_session = self.config().opt_present("remember-user-session");
Expand Down

0 comments on commit c002fd3

Please sign in to comment.