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

Add spinner wait for project new and project status --follow #503

Merged
merged 4 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
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
Next Next commit
feat: Add --follow argument to project status command
This allow the user to see update of a project command, while is
creating or removing.

Signed-off-by: Federico Guerinoni <guerinoni.federico@gmail.com>
  • Loading branch information
guerinoni authored and oddgrd committed Dec 7, 2022
commit 714ddf53bdbd37777f23648e292a9835a69810bd
6 changes: 5 additions & 1 deletion cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ pub enum ProjectCommand {
/// remove this project environment from shuttle
Rm,
/// show the status of this project's environment on shuttle
Status,
Status {
#[clap(short, long)]
/// Follow status of project command
follow: bool,
},
}

#[derive(Parser, Clone, Debug)]
Expand Down
47 changes: 43 additions & 4 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ impl Shuttle {
Command::Secrets => self.secrets(&client).await,
Command::Auth(auth_args) => self.auth(auth_args, &client).await,
Command::Project(ProjectCommand::New) => self.project_create(&client).await,
Command::Project(ProjectCommand::Status) => self.project_status(&client).await,
Command::Project(ProjectCommand::Status { follow }) => {
self.project_status(&client, follow).await
}
Command::Project(ProjectCommand::Rm) => self.project_delete(&client).await,
_ => {
unreachable!("commands that don't need a client have already been matched")
Expand Down Expand Up @@ -523,11 +525,48 @@ impl Shuttle {
Ok(())
}

async fn project_status(&self, client: &Client) -> Result<()> {
let project = client.get_project(self.ctx.project_name()).await?;
async fn project_status(&self, client: &Client, follow: bool) -> Result<()> {
let mut project = client.get_project(self.ctx.project_name()).await?;

match follow {
true => {
let pb = indicatif::ProgressBar::new_spinner();
pb.enable_steady_tick(std::time::Duration::from_millis(100));
pb.set_style(
indicatif::ProgressStyle::with_template("{spinner:.blue} {msg}")
.unwrap()
.tick_strings(&[
"( ● )",
"( ● )",
"( ● )",
"( ● )",
"( ●)",
"( ● )",
"( ● )",
"( ● )",
"( ● )",
"(● )",
"(●●●●●●)",
]),
);

println!("{project}");
loop {
if project.state == project::State::Ready
|| project.state == project::State::Destroyed
{
break;
}

pb.set_message(format!("{project}"));
project = client.get_project(self.ctx.project_name()).await?;
}

pb.finish_with_message("Done");
}
false => (),
}

println!("{project}");
Ok(())
}

Expand Down