@smbcloud / cli / commits / 5ae5ec5

check project synch

Seto Elkahfi committed May 28, 2025 at 21:52 UTC 5ae5ec5f71171ff7ce990d046382d62f1d0f5336
3 files changed +39 -19
crates/cli/src/deploy/config.rs
+32 -12
@@ -3,6 +3,8 @@ use std::{fs, path::Path};
3 use crate::ui::{fail_message, fail_symbol, succeed_message, succeed_symbol};
4 use git2::{Cred, CredentialType, Error};
5 use serde::Deserialize;
6 +use smbcloud_networking::environment::Environment;
7 +use smbcloud_networking_project::get_project;
8 use spinners::Spinner;
9 use thiserror::Error;
10
@@ -22,10 +24,7 @@ pub(crate) async fn check_config() -> Result<Config, ConfigError> {
24 }
25
26 // Parse toml file
25 - let config_content = fs::read_to_string(config_path)
26 - .map_err(|_| {
27 - ConfigError::MissingConfig
28 - })?;
27 + let config_content = fs::read_to_string(config_path).map_err(|_| ConfigError::MissingConfig)?;
28
29 let config: Config = match toml::from_str(&config_content) {
30 Ok(value) => value,
@@ -33,23 +32,42 @@ pub(crate) async fn check_config() -> Result<Config, ConfigError> {
32 println!("{}", e);
33 spinner.stop_and_persist(&fail_symbol(), fail_message("Config unsync."));
34 handle_config_error()?
36 - },
35 + }
36 };
38 -
39 - spinner.stop_and_persist(&succeed_symbol(), succeed_message("Valid config."));
37 + spinner.stop_and_persist(
38 + &succeed_symbol(),
39 + succeed_message(&format!("Valid config for {}", config.name)),
40 + );
41
42 Ok(config)
43 }
44
44 -fn handle_config_error() -> Result<Config, ConfigError> {
45 - todo!()
45 +fn handle_config_error() -> Result<Config, ConfigError> {
46 + todo!()
47 +}
48 +
49 +pub(crate) async fn check_project(env: Environment, id: i32) -> Result<(), ConfigError> {
50 + let mut spinner: Spinner = Spinner::new(
51 + spinners::Spinners::Hamburger,
52 + succeed_message("Validate project"),
53 + );
54 + match get_project(env, id.to_string()).await {
55 + Ok(_) => {
56 + spinner.stop_and_persist(&succeed_symbol(), succeed_message("Valid project"));
57 + Ok(())
58 + }
59 + Err(_) => {
60 + spinner.stop_and_persist(&fail_symbol(), succeed_message("Project is unsynched"));
61 + Err(ConfigError::ProjectNotFound)
62 + }
63 + }
64 }
65
66 #[derive(Deserialize)]
67 pub struct Config {
68 pub name: String,
69 pub description: String,
52 - pub repository: Repository
70 + pub repository: Repository,
71 }
72
73 #[derive(Deserialize)]
@@ -81,8 +99,10 @@ impl Config {
99
100 #[derive(Error, Debug, PartialEq, Eq)]
101 pub enum ConfigError {
84 - #[error("Missing config.")]
102 + #[error("Missing config file. Please regenerate with 'smb init'.")]
103 MissingConfig,
86 - #[error("Missing id in repository")]
104 + #[error("Missing id in repository. Please regenerate with 'smb init'.")]
105 MissingId,
106 + #[error("Could not find project in your list. Make sure you have access to the project.")]
107 + ProjectNotFound,
108 }
crates/cli/src/deploy/mod.rs
+7 -3
@@ -5,6 +5,7 @@ mod remote_messages;
5 use crate::{
6 account::lib::protected_request,
7 cli::CommandResult,
8 + deploy::config::check_project,
9 ui::{fail_message, succeed_message, succeed_symbol},
10 };
11 use anyhow::{anyhow, Result};
@@ -22,6 +23,9 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
23 // Check config.
24 let config = check_config().await?;
25
26 + // Validate config with project.
27 + check_project(env, config.repository.id).await?;
28 +
29 // Check remote repository setup.
30 let repo = match Repository::open(".") {
31 Ok(repo) => repo,
@@ -54,8 +58,8 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
58 if line.contains(&build_next_app()) {
59 println!("Building the app {}", succeed_symbol());
60 }
57 - if line.contains(&start_server(&config.name)) {
58 - println!("Restarting the server {}", succeed_symbol());
61 + if line.contains(&start_server(&config.repository.name)) {
62 + println!("App restart {}", succeed_symbol());
63 }
64 }
65 }
@@ -72,7 +76,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
76
77 let spinner = Spinner::new(
78 spinners::Spinners::Hamburger,
75 - succeed_message("Deploying: "),
79 + succeed_message("Deploying > "),
80 );
81 match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
82 Ok(_) => Ok(CommandResult {
crates/cli/src/project/crud_create.rs
-4
@@ -1,4 +1,3 @@
1 -use crate::deploy::config::check_config;
1 use crate::{
2 account::lib::protected_request,
3 cli::CommandResult,
@@ -15,9 +14,6 @@ use spinners::Spinner;
14 pub async fn process_project_init(env: Environment) -> Result<CommandResult> {
15 protected_request(env).await?;
16
18 - // Check config.
19 - let config = check_config().await?;
20 -
17 let project_name = match Input::<String>::with_theme(&ColorfulTheme::default())
18 .with_prompt("Project name")
19 .interact()