Fix login command not working

This commit is contained in:
bytedream 2024-01-03 01:07:12 +01:00
parent d3837f2495
commit 99f96e3e35
2 changed files with 6 additions and 24 deletions

View file

@ -315,15 +315,9 @@ async fn crunchyroll_session(cli: &mut Cli) -> Result<Crunchyroll> {
let root_login_methods_count = cli.login_method.credentials.is_some() as u8 let root_login_methods_count = cli.login_method.credentials.is_some() as u8
+ cli.login_method.etp_rt.is_some() as u8 + cli.login_method.etp_rt.is_some() as u8
+ cli.login_method.anonymous as u8; + cli.login_method.anonymous as u8;
let mut login_login_methods_count = 0;
if let Command::Login(login) = &cli.command {
login_login_methods_count += login.login_method.credentials.is_some() as u8
+ login.login_method.etp_rt.is_some() as u8
+ login.login_method.anonymous as u8
}
let progress_handler = progress!("Logging in"); let progress_handler = progress!("Logging in");
if root_login_methods_count + login_login_methods_count == 0 { if root_login_methods_count == 0 {
if let Some(login_file_path) = login::session_file_path() { if let Some(login_file_path) = login::session_file_path() {
if login_file_path.exists() { if login_file_path.exists() {
let session = fs::read_to_string(login_file_path)?; let session = fs::read_to_string(login_file_path)?;
@ -340,29 +334,19 @@ async fn crunchyroll_session(cli: &mut Cli) -> Result<Crunchyroll> {
} }
} }
bail!("Please use a login method ('--credentials', '--etp-rt' or '--anonymous')") bail!("Please use a login method ('--credentials', '--etp-rt' or '--anonymous')")
} else if root_login_methods_count + login_login_methods_count > 1 { } else if root_login_methods_count > 1 {
bail!("Please use only one login method ('--credentials', '--etp-rt' or '--anonymous')") bail!("Please use only one login method ('--credentials', '--etp-rt' or '--anonymous')")
} }
let login_method = if login_login_methods_count > 0 { let crunchy = if let Some(credentials) = &cli.login_method.credentials {
if let Command::Login(login) = &cli.command {
login.login_method.clone()
} else {
unreachable!()
}
} else {
cli.login_method.clone()
};
let crunchy = if let Some(credentials) = &login_method.credentials {
if let Some((email, password)) = credentials.split_once(':') { if let Some((email, password)) = credentials.split_once(':') {
builder.login_with_credentials(email, password).await? builder.login_with_credentials(email, password).await?
} else { } else {
bail!("Invalid credentials format. Please provide your credentials as email:password") bail!("Invalid credentials format. Please provide your credentials as email:password")
} }
} else if let Some(etp_rt) = &login_method.etp_rt { } else if let Some(etp_rt) = &cli.login_method.etp_rt {
builder.login_with_etp_rt(etp_rt).await? builder.login_with_etp_rt(etp_rt).await?
} else if login_method.anonymous { } else if cli.login_method.anonymous {
builder.login_anonymously().await? builder.login_anonymously().await?
} else { } else {
bail!("should never happen") bail!("should never happen")

View file

@ -11,8 +11,6 @@ use std::path::PathBuf;
#[derive(Debug, clap::Parser)] #[derive(Debug, clap::Parser)]
#[clap(about = "Save your login credentials persistent on disk")] #[clap(about = "Save your login credentials persistent on disk")]
pub struct Login { pub struct Login {
#[clap(flatten)]
pub login_method: LoginMethod,
#[arg(help = "Remove your stored credentials (instead of saving them)")] #[arg(help = "Remove your stored credentials (instead of saving them)")]
#[arg(long)] #[arg(long)]
pub remove: bool, pub remove: bool,
@ -56,7 +54,7 @@ pub struct LoginMethod {
#[arg(global = true, long)] #[arg(global = true, long)]
pub etp_rt: Option<String>, pub etp_rt: Option<String>,
#[arg(help = "Login anonymously / without an account")] #[arg(help = "Login anonymously / without an account")]
#[arg(long, default_value_t = false)] #[arg(global = true, long, default_value_t = false)]
pub anonymous: bool, pub anonymous: bool,
} }