Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing a username directly #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 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,10 @@ impl Greeter {
}
}

if let Some(default_user) = greeter.default_user.clone() {
greeter.username = default_user;
}

if greeter.remember {
if let Ok(username) = get_last_user_username() {
greeter.username = username.clone();
Expand Down Expand Up @@ -257,6 +262,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 +355,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