3 files changed
+48
-34
crates/smbcloud-cli/src/deploy/git.rs
+11
-7
@@ -1,3 +1,4 @@
1
+use crate::ui::{fail_message, fail_symbol, succeed_message, succeed_symbol};
2
use anyhow::{anyhow, Result};
3
use console::style;
4
use git2::{Remote, Repository};
@@ -16,8 +17,8 @@ pub async fn remote_deployment_setup(repo: &Repository, repo_name: String) -> Re
17
Ok(remote) => remote,
18
Err(_) => {
19
spinner.stop_and_persist(
19
- "😩",
20
- "Remote deployment is not setup. Will setup remote deployment.".to_owned(),
20
+ &fail_symbol(),
21
+ fail_message("Remote deployment is not setup. Will setup remote deployment."),
22
);
23
// Present the user with a message to setup remote deployment
24
repo.remote(
@@ -25,16 +26,19 @@ pub async fn remote_deployment_setup(repo: &Repository, repo_name: String) -> Re
26
&format!("deploy@api.smbcloud.xyz:git/{}", repo_name),
27
)
28
.map_err(|e: git2::Error| {
28
- spinner.stop_and_persist("😩", e.to_string());
29
- anyhow!("Failed to setup remote deployment: {e}")
29
+ spinner.stop_and_persist(&fail_symbol(), e.to_string());
30
+ anyhow!(fail_message("Failed to setup remote deployment: {e}"))
31
})?;
31
- return Err(anyhow!(
32
+ return Err(anyhow!(fail_message(
33
"Remote deployment is not setup. Please run `git remote add smbcloud <url>`."
33
- ));
34
+ )));
35
}
36
};
37
37
- spinner.stop_and_persist("🚀", "Remote deployment setup complete.".to_owned());
38
+ spinner.stop_and_persist(
39
+ &succeed_symbol(),
40
+ succeed_message("Deployment setup complete."),
41
+ );
42
43
Ok(smbcloud)
44
}
crates/smbcloud-cli/src/deploy/mod.rs
+29
-22
@@ -1,7 +1,11 @@
1
mod git;
2
mod smb_config;
3
4
-use crate::{account::lib::protected_request, cli::CommandResult};
4
+use crate::{
5
+ account::lib::protected_request,
6
+ cli::CommandResult,
7
+ ui::{fail_message, fail_symbol},
8
+};
9
use anyhow::Result;
10
use console::style;
11
use git::remote_deployment_setup;
@@ -16,7 +20,7 @@ use std::{fs::File, io::BufReader};
20
pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
21
protected_request(env).await?;
22
let repo_name = check_config().await?;
19
- println!("Deploying your app...");
23
+
24
let mut spinner = Spinner::new(
25
spinners::Spinners::SimpleDotsScrolling,
26
style("Deploying...").green().bold().to_string(),
@@ -28,8 +32,8 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
32
spinner.stop_and_persist("😩", "No git repository found.".to_owned());
33
return Ok(CommandResult {
34
spinner,
31
- symbol: "😩".to_owned(),
32
- msg: "No git repository found. Init with `git init` command.".to_owned(),
35
+ symbol: fail_symbol(),
36
+ msg: fail_message("No git repository found. Init with `git init` command."),
37
});
38
}
39
};
@@ -40,22 +44,24 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
44
spinner.stop_and_persist("😩", "No main branch found.".to_owned());
45
return Ok(CommandResult {
46
spinner,
43
- symbol: "😩".to_owned(),
44
- msg: "No main branch found. Create with `git checkout -b <branch>` command."
45
- .to_owned(),
47
+ symbol: fail_symbol(),
48
+ msg: fail_message(
49
+ "No main branch found. Create with `git checkout -b <branch>` command.",
50
+ ),
51
});
52
}
53
};
49
- let origin = remote_deployment_setup(&repo, repo_name).await?;
54
+ let mut origin = remote_deployment_setup(&repo, repo_name).await?;
55
let remote_url = match origin.url() {
56
Some(url) => url,
57
None => {
58
spinner.stop_and_persist("😩", "No remote URL found.".to_owned());
59
return Ok(CommandResult {
60
spinner,
56
- symbol: "😩".to_owned(),
57
- msg: "No remote URL found. Add with `git remote add origin <url>` command."
58
- .to_owned(),
61
+ symbol: fail_symbol(),
62
+ msg: fail_message(
63
+ "No remote URL found. Add with `git remote add origin <url>` command.",
64
+ ),
65
});
66
}
67
};
@@ -66,7 +72,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
72
spinner.stop_and_persist("😩", e.to_string());
73
return Ok(CommandResult {
74
spinner,
69
- symbol: "😩".to_owned(),
75
+ symbol: fail_symbol(),
76
msg: "Invalid remote URL.".to_owned(),
77
});
78
}
@@ -80,8 +86,8 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
86
// Only support ssh for now
87
return Ok(CommandResult {
88
spinner,
83
- symbol: "😩".to_owned(),
84
- msg: "Only ssh is supported.".to_owned(),
89
+ symbol: fail_symbol(),
90
+ msg: fail_message("Only ssh is supported."),
91
});
92
}
93
};
@@ -93,8 +99,8 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
99
spinner.stop_and_persist("😩", "No host found.".to_owned());
100
return Ok(CommandResult {
101
spinner,
96
- symbol: "😩".to_owned(),
97
- msg: "No host found.".to_owned(),
102
+ symbol: fail_symbol(),
103
+ msg: fail_message("No host found."),
104
});
105
}
106
};
@@ -111,8 +117,8 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
117
spinner.stop_and_persist("😩", "No ssh config found.".to_owned());
118
return Ok(CommandResult {
119
spinner,
114
- symbol: "😩".to_owned(),
115
- msg: "No ssh config found.".to_owned(),
120
+ symbol: fail_symbol(),
121
+ msg: fail_message("No ssh config found."),
122
});
123
}
124
}
@@ -150,7 +156,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
156
});
157
}
158
};
153
- //println!("Identity files: {:#?}", identity_files);
159
+ println!("Identity files: {:#?}", identity_files);
160
// get identity_file
161
let identity_file = match identity_files.first() {
162
Some(identity_file) => {
@@ -170,11 +176,13 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
176
let mut callbacks = RemoteCallbacks::new();
177
// Set the credentials
178
callbacks.credentials(|_url, _username_from_url, _allowed_types| {
173
- Cred::ssh_key("git", None, identity_file, None)
179
+ Cred::ssh_key("deploy", None, identity_file, None)
180
+ });
181
+ callbacks.push_transfer_progress(|current, total, bytes| {
182
+ println!("Progress: current -> {}, total -> {}, bytes -> {}", current, total, bytes);
183
});
184
push_opts.remote_callbacks(callbacks);
185
177
- /*
186
match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
187
Ok(_) => {}
188
Err(e) => {
@@ -187,7 +195,6 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
195
});
196
}
197
};
190
- */
198
199
Ok(CommandResult {
200
spinner,
crates/smbcloud-cli/src/deploy/smb_config.rs
+8
-5
@@ -1,3 +1,4 @@
1
+use crate::ui::{fail_message, fail_symbol, succeed_message, succeed_symbol};
2
use anyhow::Result;
3
use console::style;
4
use spinners::Spinner;
@@ -13,10 +14,10 @@ pub(crate) async fn check_config() -> Result<String> {
14
// Get .smb/config.toml file path in the current directory
15
let config_path = Path::new(".smb/config.toml");
16
if !config_path.exists() {
16
- spinner.stop_and_persist("😩", "No config file found.".to_owned());
17
- return Err(anyhow::anyhow!(
17
+ spinner.stop_and_persist(&fail_symbol(), fail_message("Invalid config."));
18
+ return Err(anyhow::anyhow!(fail_message(
19
"No config file found. Please run `smbcloud init` command."
19
- ));
20
+ )));
21
}
22
23
// Parse toml file
@@ -24,10 +25,12 @@ pub(crate) async fn check_config() -> Result<String> {
25
let config: Value = toml::from_str(&config_content)?;
26
27
let repo_name = config
27
- .get("repo")
28
+ .get("repository")
29
.and_then(|repo| repo.get("name"))
30
.and_then(|name| name.as_str())
30
- .ok_or_else(|| anyhow::anyhow!("Repo name not found in config file"))?;
31
+ .ok_or_else(|| anyhow::anyhow!(fail_message("Repo name not found in config file.")))?;
32
+
33
+ spinner.stop_and_persist(&succeed_symbol(), succeed_message("Valid config."));
34
35
Ok(repo_name.to_string())
36
}