-
Notifications
You must be signed in to change notification settings - Fork 254
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
feat: Rename project new/rm
to start/stop
, add restart
+ other args fixes
#771
Changes from all commits
c4bfb80
67dcefa
10c732c
3146178
5410c3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ use std::path::{Path, PathBuf}; | |
use std::process::exit; | ||
use std::str::FromStr; | ||
|
||
use anyhow::{anyhow, bail, Context, Result}; | ||
use anyhow::{bail, Context, Result}; | ||
pub use args::{Args, Command, DeployArgs, InitArgs, LoginArgs, ProjectArgs, RunArgs}; | ||
use cargo_metadata::Message; | ||
use clap::CommandFactory; | ||
|
@@ -69,7 +69,13 @@ impl Shuttle { | |
Command::Deploy(..) | ||
| Command::Deployment(..) | ||
| Command::Resource(..) | ||
| Command::Project(..) | ||
| Command::Project( | ||
// ProjectCommand::List does not need to know which project we are in | ||
ProjectCommand::Start { .. } | ||
| ProjectCommand::Stop { .. } | ||
| ProjectCommand::Restart { .. } | ||
| ProjectCommand::Status { .. } | ||
) | ||
| Command::Stop | ||
| Command::Clean | ||
| Command::Secrets | ||
|
@@ -104,16 +110,19 @@ impl Shuttle { | |
Command::Stop => self.stop(&self.client()?).await, | ||
Command::Clean => self.clean(&self.client()?).await, | ||
Command::Secrets => self.secrets(&self.client()?).await, | ||
Command::Project(ProjectCommand::New { idle_minutes }) => { | ||
Command::Project(ProjectCommand::Start { idle_minutes }) => { | ||
self.project_create(&self.client()?, idle_minutes).await | ||
} | ||
Command::Project(ProjectCommand::Restart { idle_minutes }) => { | ||
self.project_recreate(&self.client()?, idle_minutes).await | ||
} | ||
Command::Project(ProjectCommand::Status { follow }) => { | ||
self.project_status(&self.client()?, follow).await | ||
} | ||
Command::Project(ProjectCommand::List { filter }) => { | ||
self.projects_list(&self.client()?, filter).await | ||
} | ||
Command::Project(ProjectCommand::Rm) => self.project_delete(&self.client()?).await, | ||
Command::Project(ProjectCommand::Stop) => self.project_delete(&self.client()?).await, | ||
} | ||
.map(|_| CommandOutcome::Ok) | ||
} | ||
|
@@ -344,7 +353,7 @@ impl Shuttle { | |
if let Some(deployment) = summary.deployment { | ||
deployment.id | ||
} else { | ||
return Err(anyhow!("could not automatically find a running deployment for '{}'. Try passing a deployment ID manually", self.ctx.project_name())); | ||
bail!("Could not automatically find a running deployment for '{}'. Try passing a deployment ID manually", self.ctx.project_name()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't quite remember, but doesn't There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From https://docs.rs/anyhow/latest/anyhow/macro.bail.html
I'd be surprised if that actually affected formatting 🧐 |
||
} | ||
}; | ||
|
||
|
@@ -728,6 +737,13 @@ impl Shuttle { | |
Ok(()) | ||
} | ||
|
||
async fn project_recreate(&self, client: &Client, idle_minutes: u64) -> Result<()> { | ||
self.project_delete(client).await?; | ||
self.project_create(client, idle_minutes).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn projects_list(&self, client: &Client, filter: Option<String>) -> Result<()> { | ||
let projects = match filter { | ||
Some(filter) => { | ||
|
@@ -736,7 +752,7 @@ impl Shuttle { | |
.get_projects_list_filtered(filter.to_string()) | ||
.await? | ||
} else { | ||
return Err(anyhow!("That's not a valid project status!")); | ||
bail!("That's not a valid project status!"); | ||
} | ||
} | ||
None => client.get_projects_list().await?, | ||
|
@@ -750,26 +766,23 @@ impl Shuttle { | |
} | ||
|
||
async fn project_status(&self, client: &Client, follow: bool) -> Result<()> { | ||
match follow { | ||
true => { | ||
self.wait_with_spinner( | ||
&[ | ||
project::State::Ready, | ||
project::State::Destroyed, | ||
project::State::Errored { | ||
message: Default::default(), | ||
}, | ||
], | ||
client.get_project(self.ctx.project_name()), | ||
self.ctx.project_name(), | ||
client, | ||
) | ||
.await?; | ||
} | ||
false => { | ||
let project = client.get_project(self.ctx.project_name()).await?; | ||
println!("{project}"); | ||
} | ||
if follow { | ||
self.wait_with_spinner( | ||
&[ | ||
project::State::Ready, | ||
project::State::Destroyed, | ||
project::State::Errored { | ||
message: Default::default(), | ||
}, | ||
], | ||
client.get_project(self.ctx.project_name()), | ||
self.ctx.project_name(), | ||
client, | ||
) | ||
.await?; | ||
} else { | ||
let project = client.get_project(self.ctx.project_name()).await?; | ||
println!("{project}"); | ||
} | ||
|
||
Ok(()) | ||
|
@@ -917,9 +930,9 @@ impl Shuttle { | |
} | ||
|
||
writeln!(error).expect("to append error"); | ||
writeln!(error, "to proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag").expect("to append error"); | ||
writeln!(error, "To proceed despite this and include the uncommitted changes, pass the `--allow-dirty` flag").expect("to append error"); | ||
|
||
return Err(anyhow::Error::msg(error)); | ||
bail!(error); | ||
} | ||
} | ||
|
||
|
@@ -955,9 +968,7 @@ fn check_version(runtime_path: &Path) -> Result<()> { | |
if runtime_version == valid_version { | ||
Ok(()) | ||
} else { | ||
Err(anyhow!( | ||
"shuttle-runtime and cargo-shuttle are not the same version" | ||
)) | ||
bail!("shuttle-runtime and cargo-shuttle are not the same version") | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one 😍