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

fix(cargo-shuttle): fix init login bugs #1309

Merged
merged 3 commits into from Oct 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 20 additions & 12 deletions cargo-shuttle/src/lib.rs
Expand Up @@ -303,22 +303,30 @@ impl Shuttle {
// Turns the template or git args (if present) to a repo+folder.
let git_templates = args.git_template()?;

let interactive =
project_args.name.is_none() || git_templates.is_none() || !provided_path_to_init;
let unauthorized = self.ctx.api_key().is_err() && args.login_args.api_key.is_none();

let interactive = project_args.name.is_none()
|| git_templates.is_none()
|| !provided_path_to_init
|| unauthorized;

let theme = ColorfulTheme::default();

// 1. Log in (if not logged in yet)
if self.ctx.api_key().is_err() {
if interactive {
println!("First, let's log in to your Shuttle account.");
self.login(args.login_args.clone()).await?;
println!();
} else if args.login_args.api_key.is_some() {
self.login(args.login_args.clone()).await?;
} else if args.create_env {
bail!("Tried to login to create a Shuttle environment, but no API key was set.")
}
if let Ok(api_key) = self.ctx.api_key() {
let login_args = LoginArgs {
api_key: Some(api_key.as_ref().to_string()),
};

self.login(login_args).await?;
} else if interactive {
println!("First, let's log in to your Shuttle account.");
self.login(args.login_args.clone()).await?;
println!();
} else if args.login_args.api_key.is_some() {
self.login(args.login_args.clone()).await?;
} else if args.create_env {
bail!("Tried to login to create a Shuttle environment, but no API key was set.")
}

// 2. Ask for project name
Expand Down