@smbcloud / cli / commits / 503e4b2

Display in table

Seto Elkahfi committed Mar 18, 2023 at 00:07 UTC 503e4b2142b8fef1a9d5f14d4979959e1716b083
2 files changed +16 -6
src/projects/crud/mod.rs
+5 -5
@@ -5,10 +5,10 @@ use serde::Deserialize;
5
6 #[derive(Deserialize, Debug)]
7 pub struct Project {
8 - id: i32,
9 - name: String,
10 - created_at: String,
11 - updated_at: String,
8 + pub id: i32,
9 + pub name: String,
10 + pub created_at: String,
11 + pub updated_at: String,
12 }
13
14 pub async fn get_all() -> Result<Vec<Project>> {
@@ -28,7 +28,7 @@ pub async fn get_all() -> Result<Vec<Project>> {
28 }
29 _ => {
30 debug!("Failed to get all projects.", response.status());
31 - Err(anyhow!("Failed to login."))
31 + Err(anyhow!("Failed to fetch projects."))
32 }
33 }
34 }
src/projects/mod.rs
+11 -1
@@ -39,7 +39,7 @@ pub enum Commands {
39 pub async fn process(commands: Commands) -> Result<CommandResult> {
40 let spinner = Spinner::new(
41 spinners::Spinners::SimpleDotsScrolling,
42 - style("Logging in...").green().bold().to_string(),
42 + style("Loading...").green().bold().to_string(),
43 );
44 match commands {
45 Commands::New { name } => {
@@ -59,6 +59,16 @@ pub async fn process(commands: Commands) -> Result<CommandResult> {
59 match get_all().await {
60 Ok(projects) => {
61 println!("Projects: {:#?}", projects);
62 + println!(
63 + "{0: <5} | {1: <20} | {2: <30} | {3: <30}",
64 + "ID", "Name", "Created at", "Updated at"
65 + );
66 + for project in projects {
67 + println!(
68 + "{0: <5} | {1: <20} | {2: <30} | {3: <30}",
69 + project.id, project.name, project.created_at, project.updated_at
70 + );
71 + }
72 Ok(CommandResult {
73 spinner,
74 symbol: "✅".to_owned(),