Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Heliozoa committed Mar 14, 2022
1 parent b126670 commit 7848cfe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 25 deletions.
14 changes: 2 additions & 12 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@ pub fn handle(matches: &clap::ArgMatches, io: &mut dyn Io) {

match matches.subcommand() {
Some(("login", args)) => {
let interactive_mode;
if args.is_present("non-interactive") {
interactive_mode = false;
} else {
interactive_mode = true;
}
let interactive_mode = !args.is_present("non-interactive");
login(io, &mut client, interactive_mode)
}
Some(("download", args)) => download_or_update(
Expand All @@ -79,12 +74,7 @@ pub fn handle(matches: &clap::ArgMatches, io: &mut dyn Io) {
update(io, &mut client, args.is_present("currentdir"));
}
Some(("organization", args)) => {
let interactive_mode;
if args.is_present("non-interactive") {
interactive_mode = false;
} else {
interactive_mode = true;
}
let interactive_mode = !args.is_present("non-interactive");
organization(io, &mut client, interactive_mode)
}
Some(("courses", _)) => list_courses(io, &mut client),
Expand Down
7 changes: 1 addition & 6 deletions src/commands/command_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ impl Client for ClientProduction {
}

fn try_login(&mut self, username: String, password: String) -> Result<String, String> {
let token;

if self.test_mode {
if username == "testusername" && password == "testpassword" {
let mut config = TmcConfig::load(PLUGIN, &get_path()).unwrap();
Expand All @@ -193,11 +191,8 @@ impl Client for ClientProduction {
}
return Err(WRONG_LOGIN.to_string());
}
match self.authenticate(username, password) {
Ok(x) => token = x,
Err(x) => return Err(x),
}

let token = self.authenticate(username, password)?;
if Credentials::save(PLUGIN, token).is_ok() {
return Ok(SUCCESSFUL_LOGIN.to_string());
};
Expand Down
10 changes: 4 additions & 6 deletions src/commands/login_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,13 @@ pub fn login(io: &mut dyn Io, client: &mut dyn Client, interactive_mode: bool) {

io.print("Password: ", PrintColor::Normal);

let mut password;

// Read password without rpassword if ran in --testmode, because rpassword
// is not able to read mock stdin input in binary tests
if client.is_test_mode() {
password = io.read_line();
let mut password = if client.is_test_mode() {
io.read_line()
} else {
password = io.read_password();
}
io.read_password()
};
password = password.trim().to_string();

match client.try_login(username, password) {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/submit_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn print_wait_for_submission_results(io: &mut dyn Io, submission_finished: Submi
} else {
io.println(&format!("Failed: {}", case.name), PrintColor::Failed);
if let Some(message) = case.message {
let formatted = message.replace("\n", "\n ");
let formatted = message.replace('\n', "\n ");
io.println(&format!(" {}", formatted), PrintColor::Normal);
}
io.println("", PrintColor::Normal);
Expand Down

0 comments on commit 7848cfe

Please sign in to comment.