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

use config file to logout #38

Merged
merged 7 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
fix: 修改文本
1328411791 committed Jan 30, 2024
commit 1f3a2135121fc9a3808f80e153bb2ef7419bdc13
13 changes: 6 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ fn logout_match(args: &[String]) {
opts.optopt("u", "username", "username", "");
opts.optopt("i", "ip", "ip", "");
opts.optflag("d", "detect", "detect client ip");
opts.optopt("c","config","logout by config","");
opts.optopt("c", "config", "logout by config file", "");
opts.optflag("", "select-ip", "select client ip");
opts.optflag("", "strict-bind", "strict bind ip");
opts.optopt("", "acid", "acid", "");
@@ -98,8 +98,7 @@ fn logout_match(args: &[String]) {
print_usage(Some(&options));
} else if matches.opt_present("c") {
config_logout(matches);
}
else {
} else {
logout(matches)
}
}
@@ -240,7 +239,7 @@ fn single_login(matches: Matches) {
}
}

fn config_logout(matches: Matches){
fn config_logout(matches: Matches) {
let config_path = matches.opt_str("c").unwrap();
match read_config_from_file(config_path) {
Ok(config) => {
@@ -254,9 +253,9 @@ fn config_logout(matches: Matches){
});
for user in config_i {
println!("logout user: {:#?}", user);
let ip = user
.ip
.unwrap_or_else(|| get_ip_by_if_name(&user.if_name.unwrap_or_default()).unwrap_or_default());
let ip = user.ip.unwrap_or_else(|| {
get_ip_by_if_name(&user.if_name.unwrap_or_default()).unwrap_or_default()
});
let mut client = SrunClient::new_for_logout(&auth_server, &user.username, &ip)
.set_detect_ip(config.detect_ip)
.set_strict_bind(config.strict_bind);