diff --git a/cargo-shuttle/src/lib.rs b/cargo-shuttle/src/lib.rs index 5305a783e..a7d1f46f3 100644 --- a/cargo-shuttle/src/lib.rs +++ b/cargo-shuttle/src/lib.rs @@ -734,13 +734,20 @@ impl Shuttle { println!(); return Ok(CommandOutcome::Ok); } + let limit = limit + 1; let proj_name = self.ctx.project_name(); - let deployments = client + let mut deployments = client .get_deployments(proj_name, page, limit) .await .map_err(suggestions::deployment::get_deployments_list_failure)?; - let table = get_deployments_table(&deployments, proj_name.as_str(), page, raw); + let page_hint = if deployments.len() == limit as usize { + deployments.pop(); + true + } else { + false + }; + let table = get_deployments_table(&deployments, proj_name.as_str(), page, raw, page_hint); println!("{table}"); println!("Run `cargo shuttle logs ` to get logs for a given deployment."); @@ -1695,8 +1702,9 @@ impl Shuttle { println!(); return Ok(CommandOutcome::Ok); } + let limit = limit + 1; - let projects = client.get_projects_list(page, limit).await.map_err(|err| { + let mut projects = client.get_projects_list(page, limit).await.map_err(|err| { suggestions::project::project_request_failure( err, "Getting projects list failed", @@ -1704,7 +1712,13 @@ impl Shuttle { "getting the projects list fails repeteadly", ) })?; - let projects_table = project::get_projects_table(&projects, page, raw); + let page_hint = if projects.len() == limit as usize { + projects.pop(); + true + } else { + false + }; + let projects_table = project::get_projects_table(&projects, page, raw, page_hint); println!("{projects_table}"); diff --git a/common/src/models/deployment.rs b/common/src/models/deployment.rs index 4b8e8e628..cc0f7945e 100644 --- a/common/src/models/deployment.rs +++ b/common/src/models/deployment.rs @@ -76,6 +76,7 @@ pub fn get_deployments_table( service_name: &str, page: u32, raw: bool, + page_hint: bool, ) -> String { if deployments.is_empty() { // The page starts at 1 in the CLI. @@ -196,9 +197,15 @@ pub fn get_deployments_table( } } - format!( - "\nMost recent deployments for {service_name}\n{table}\nMore projects might be available on the next page using --page.\n", - ) + let formatted_table = format!("\nMost recent deployments for {service_name}\n{table}\n"); + if page_hint { + format!( + "{formatted_table}More deployments are available on the next page using `--page {}`\n", + page + 1 + ) + } else { + formatted_table + } } } diff --git a/common/src/models/project.rs b/common/src/models/project.rs index 1ef395ccd..5eb1cc26f 100644 --- a/common/src/models/project.rs +++ b/common/src/models/project.rs @@ -191,7 +191,12 @@ pub struct AdminResponse { pub account_name: String, } -pub fn get_projects_table(projects: &Vec, page: u32, raw: bool) -> String { +pub fn get_projects_table( + projects: &Vec, + page: u32, + raw: bool, + page_hint: bool, +) -> String { if projects.is_empty() { // The page starts at 1 in the CLI. let mut s = if page <= 1 { @@ -244,8 +249,14 @@ pub fn get_projects_table(projects: &Vec, page: u32, raw: bool) -> Str } } - format!( - "\nThese projects are linked to this account\n{table}\nMore projects might be available on the next page using --page.\n" - ) + let formatted_table = format!("\nThese projects are linked to this account\n{table}\n"); + if page_hint { + format!( + "{formatted_table}More projects are available on the next page using `--page {}`\n", + page + 1 + ) + } else { + formatted_table + } } }