@smbcloud / cli / commits / dc3d8bd

cleanup

Seto Elkahfi committed May 29, 2025 at 01:30 UTC dc3d8bdd548415fca54be3bb6b3d9c2f92a5d299
4 files changed +73 -61
crates/cli/src/project/cli.rs
+2 -2
@@ -26,10 +26,10 @@ pub enum Commands {
26 Use {
27 #[clap(short, long, required = true)]
28 id: String,
29 - },
29 + },
30 #[clap(about = "Manage project deployment. Pass --id to get detail deployment.")]
31 Deployment {
32 #[clap(short, long)]
33 id: Option<String>,
34 - }
34 + },
35 }
crates/cli/src/project/deployment.rs
+30 -20
@@ -1,20 +1,23 @@
1 +use crate::{
2 + cli::CommandResult,
3 + deploy::config::check_config,
4 + ui::{succeed_message, succeed_symbol},
5 +};
6 +use anyhow::Result;
7 +use smbcloud_model::project::Deployment;
8 use smbcloud_networking::environment::Environment;
2 -use smbcloud_networking_project::crud_project_deployment_read::{get_deployment_detail, list_deployments};
9 +use smbcloud_networking_project::crud_project_deployment_read::{
10 + get_deployment_detail, list_deployments,
11 +};
12 use spinners::Spinner;
4 -use crate::{cli::CommandResult, deploy::config::check_config, ui::{succeed_message, succeed_symbol}};
5 -use anyhow::{anyhow, Result};
6 -use smbcloud_model::project::Config;
7 -use std::fs;
8 -use dirs;
13 use tabled::{Table, Tabled};
10 -use smbcloud_model::project::Deployment;
14
12 -pub(crate) async fn process_deployment(env: Environment, id: Option<String>) -> Result<CommandResult> {
13 -
14 - let mut spinner: Spinner = Spinner::new(
15 - spinners::Spinners::Hamburger,
16 - succeed_message("Loading"),
17 - );
15 +pub(crate) async fn process_deployment(
16 + env: Environment,
17 + id: Option<String>,
18 +) -> Result<CommandResult> {
19 + let mut spinner: Spinner =
20 + Spinner::new(spinners::Spinners::Hamburger, succeed_message("Loading"));
21 // Load project id from .smb/config.toml
22 let config = check_config().await?;
23
@@ -31,10 +34,11 @@ pub(crate) async fn process_deployment(env: Environment, id: Option<String>) ->
34 show_project_deployments(&deployments);
35 };
36
34 - Ok(CommandResult { spinner: Spinner::new(
35 - spinners::Spinners::Hamburger,
36 - succeed_message("Loading."),
37 - ), symbol: succeed_symbol(), msg: succeed_message("Loaded") })
37 + Ok(CommandResult {
38 + spinner: Spinner::new(spinners::Spinners::Hamburger, succeed_message("Loading.")),
39 + symbol: succeed_symbol(),
40 + msg: succeed_message("Loaded"),
41 + })
42 }
43
44 // Helper struct for table display
@@ -85,10 +89,16 @@ pub fn show_deployment_detail(deployment: &Deployment) {
89 project_id: deployment.project_id,
90 commit_hash: deployment.commit_hash.clone(),
91 status: format!("{:?}", deployment.status),
88 - created_at: deployment.created_at.format("%Y-%m-%d %H:%M:%S").to_string(),
89 - updated_at: deployment.updated_at.format("%Y-%m-%d %H:%M:%S").to_string(),
92 + created_at: deployment
93 + .created_at
94 + .format("%Y-%m-%d %H:%M:%S")
95 + .to_string(),
96 + updated_at: deployment
97 + .updated_at
98 + .format("%Y-%m-%d %H:%M:%S")
99 + .to_string(),
100 };
101
102 let table = Table::new(vec![row]);
103 println!("{table}");
94 -}
\ No newline at end of file
104 +}
crates/cli/src/project/mod.rs
+39 -34
@@ -7,7 +7,12 @@ mod deployment;
7 use self::cli::Commands;
8 use crate::{
9 cli::CommandResult,
10 - project::{crud_create::process_project_init, crud_delete::process_project_delete, crud_read::{process_project_list, process_project_show}, deployment::process_deployment},
10 + project::{
11 + crud_create::process_project_init,
12 + crud_delete::process_project_delete,
13 + crud_read::{process_project_list, process_project_show},
14 + deployment::process_deployment,
15 + },
16 ui::{succeed_message, succeed_symbol},
17 };
18 use anyhow::{anyhow, Result};
@@ -25,40 +30,40 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
30 Commands::Show { id } => process_project_show(env, id).await,
31 Commands::Delete { id } => process_project_delete(env, id).await,
32 Commands::Use { id } => {
28 - let project = get_project(env, id).await?;
29 -
30 - let config = Config {
31 - current_project: Some(project),
32 - current_auth_app: None,
33 - };
34 -
35 - let spinner = Spinner::new(
36 - spinners::Spinners::SimpleDotsScrolling,
37 - succeed_message("Loading"),
38 - );
39 - match home::home_dir() {
40 - Some(path) => {
41 - debug!("{}", path.to_str().unwrap());
42 - let mut file = OpenOptions::new()
43 - .create(true)
44 - .truncate(true)
45 - .write(true)
46 - .open([path.to_str().unwrap(), "/.smb/config.json"].join(""))?;
47 - let json = serde_json::to_string(&config)?;
48 - file.write_all(json.as_bytes())?;
49 -
50 - Ok(CommandResult {
51 - spinner,
52 - symbol: succeed_symbol(),
53 - msg: succeed_message("Use project successful."),
54 - })
55 - }
56 - None => {
57 - let error = anyhow!("Failed to get home directory.");
58 - Err(error)
59 - }
60 - }
33 + let project = get_project(env, id).await?;
34 +
35 + let config = Config {
36 + current_project: Some(project),
37 + current_auth_app: None,
38 + };
39 +
40 + let spinner = Spinner::new(
41 + spinners::Spinners::SimpleDotsScrolling,
42 + succeed_message("Loading"),
43 + );
44 + match home::home_dir() {
45 + Some(path) => {
46 + debug!("{}", path.to_str().unwrap());
47 + let mut file = OpenOptions::new()
48 + .create(true)
49 + .truncate(true)
50 + .write(true)
51 + .open([path.to_str().unwrap(), "/.smb/config.json"].join(""))?;
52 + let json = serde_json::to_string(&config)?;
53 + file.write_all(json.as_bytes())?;
54 +
55 + Ok(CommandResult {
56 + spinner,
57 + symbol: succeed_symbol(),
58 + msg: succeed_message("Use project successful."),
59 + })
60 + }
61 + None => {
62 + let error = anyhow!("Failed to get home directory.");
63 + Err(error)
64 + }
65 }
66 + }
67 Commands::Deployment { id } => process_deployment(env, id).await,
68 }
69 }
crates/smbcloud-networking-project/src/crud_project_deployment_read.rs
+2 -5
@@ -4,10 +4,7 @@ use reqwest::Client;
4 use smbcloud_model::project::Deployment;
5 use smbcloud_networking::{environment::Environment, get_smb_token};
6
7 -pub async fn list_deployments(
8 - env: Environment,
9 - project_id: i32,
10 -) -> Result<Vec<Deployment>> {
7 +pub async fn list_deployments(env: Environment, project_id: i32) -> Result<Vec<Deployment>> {
8 let token = get_smb_token(env).await?;
9
10 let response = Client::new()
@@ -49,4 +46,4 @@ pub async fn get_deployment_detail(
46 }
47 _ => Err(anyhow!("Failed to get deployment detail.")),
48 }
52 -}
\ No newline at end of file
49 +}