23 files changed
+90
-18
Cargo.lock
+36
@@ -873,6 +873,19 @@ dependencies = [
873
"hashbrown",
874
]
875
876
+[[package]]
877
+name = "indicatif"
878
+version = "0.17.11"
879
+source = "registry+https://github.com/rust-lang/crates.io-index"
880
+checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
881
+dependencies = [
882
+ "console",
883
+ "number_prefix",
884
+ "portable-atomic",
885
+ "unicode-width",
886
+ "web-time",
887
+]
888
+
889
[[package]]
890
name = "ipnet"
891
version = "2.11.0"
@@ -1120,6 +1133,12 @@ dependencies = [
1133
"autocfg",
1134
]
1135
1136
+[[package]]
1137
+name = "number_prefix"
1138
+version = "0.4.0"
1139
+source = "registry+https://github.com/rust-lang/crates.io-index"
1140
+checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
1141
+
1142
[[package]]
1143
name = "object"
1144
version = "0.36.7"
@@ -1255,6 +1274,12 @@ version = "0.3.32"
1274
source = "registry+https://github.com/rust-lang/crates.io-index"
1275
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
1276
1277
+[[package]]
1278
+name = "portable-atomic"
1279
+version = "1.11.0"
1280
+source = "registry+https://github.com/rust-lang/crates.io-index"
1281
+checksum = "350e9b48cbc6b0e028b0473b114454c6316e57336ee184ceab6e53f72c178b3e"
1282
+
1283
[[package]]
1284
name = "powerfmt"
1285
version = "0.2.0"
@@ -1654,6 +1679,7 @@ dependencies = [
1679
"git-url-parse",
1680
"git2",
1681
"home",
1682
+ "indicatif",
1683
"log",
1684
"open",
1685
"regex",
@@ -2408,6 +2434,16 @@ dependencies = [
2434
"wasm-bindgen",
2435
]
2436
2437
+[[package]]
2438
+name = "web-time"
2439
+version = "1.1.0"
2440
+source = "registry+https://github.com/rust-lang/crates.io-index"
2441
+checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
2442
+dependencies = [
2443
+ "js-sys",
2444
+ "wasm-bindgen",
2445
+]
2446
+
2447
[[package]]
2448
name = "wildmatch"
2449
version = "2.4.0"
Cargo.toml
+2
-1
@@ -1,7 +1,7 @@
1
[workspace]
2
resolver = "2"
3
members = [
4
- "crates/smbcloud-cli",
4
+ "crates/cli",
5
"crates/smbcloud-model",
6
"crates/smbcloud-networking",
7
"crates/smbcloud-networking-project",
@@ -42,3 +42,4 @@ url = "2"
42
url-builder = "0.1.1"
43
dirs = "5.0"
44
reqwest = "0.12"
45
+indicatif = "0.17.11"
crates/cli/Cargo.toml
renamed
+1
@@ -23,6 +23,7 @@ console = { workspace = true }
23
dialoguer = { workspace = true }
24
dirs = { workspace = true }
25
home = { workspace = true }
26
+indicatif = { workspace = true }
27
log = { workspace = true }
28
git2 = { workspace = true }
29
ssh2-config = { workspace = true }
crates/cli/README.md
renamed
crates/cli/src/account/cli.rs
renamed
crates/cli/src/account/forgot/mod.rs
renamed
crates/cli/src/account/lib.rs
renamed
crates/cli/src/account/login/mod.rs
renamed
crates/cli/src/account/login/process.rs
renamed
crates/cli/src/account/logout/mod.rs
renamed
crates/cli/src/account/mod.rs
renamed
crates/cli/src/account/signup/mod.rs
renamed
crates/cli/src/account/signup/process.rs
renamed
crates/cli/src/cli/mod.rs
renamed
crates/cli/src/deploy/git.rs
renamed
crates/cli/src/deploy/mod.rs
renamed
+49
-17
@@ -4,18 +4,19 @@ mod smb_config;
4
use crate::{
5
account::lib::protected_request,
6
cli::CommandResult,
7
- ui::{fail_message, fail_symbol},
7
+ ui::{fail_message, fail_symbol, succeed_message, succeed_symbol},
8
};
9
use anyhow::Result;
10
use console::style;
11
use git::remote_deployment_setup;
12
use git2::{Cred, PushOptions, RemoteCallbacks, Repository};
13
use git_url_parse::{GitUrl, Scheme};
14
+use indicatif::{ProgressBar, ProgressState, ProgressStyle};
15
use smb_config::check_config;
16
use smbcloud_networking::environment::Environment;
17
use spinners::Spinner;
18
use ssh2_config::{ParseRule, SshConfig};
18
-use std::{fs::File, io::BufReader};
19
+use std::{cmp::min, fmt::Write, fs::File, io::BufReader};
20
21
pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
22
protected_request(env).await?;
@@ -156,7 +157,7 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
157
});
158
}
159
};
159
- println!("Identity files: {:#?}", identity_files);
160
+ // println!("Identity files: {:#?}", identity_files);
161
// get identity_file
162
let identity_file = match identity_files.first() {
163
Some(identity_file) => {
@@ -179,26 +180,57 @@ pub async fn process_deploy(env: Environment) -> Result<CommandResult> {
180
Cred::ssh_key("deploy", None, identity_file, None)
181
});
182
callbacks.push_transfer_progress(|current, total, bytes| {
182
- println!("Progress: current -> {}, total -> {}, bytes -> {}", current, total, bytes);
183
+ // println!("push_transfer_progress: current -> {}, total -> {}, bytes -> {}", current, total, bytes);
184
+ let pb = ProgressBar::new(total.try_into().unwrap());
185
+ pb.set_style(ProgressStyle::with_template("{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})")
186
+ .unwrap()
187
+ .with_key("eta", |state: &ProgressState, w: &mut dyn Write| write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap())
188
+ .progress_chars("#>-"));
189
+ let mut current = current;
190
+ while current < total {
191
+ let new = min(current + 223211, total);
192
+ current = new;
193
+ pb.set_position(new.try_into().unwrap());
194
+ }
195
+
196
+ pb.finish_with_message("downloaded");
197
+ });
198
+ callbacks.pack_progress(|stage, current, total| {
199
+ println!("pack_progress: current -> {}, total -> {}", current, total);
200
+ });
201
+ callbacks.sideband_progress(|x| {
202
+ //println!("{x}");
203
+ return true;
204
+ });
205
+ callbacks.push_update_reference(|x, y| match y {
206
+ Some(e) => {
207
+ println!("{}", e);
208
+ Ok(())
209
+ }
210
+ None => {
211
+ println!("Done");
212
+ Ok(())
213
+ }
214
});
215
push_opts.remote_callbacks(callbacks);
216
186
- match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
187
- Ok(_) => {}
217
+ return match origin.push(&["refs/heads/main:refs/heads/main"], Some(&mut push_opts)) {
218
+ Ok(_) => {
219
+ println!("Succeed!!!");
220
+ Ok(CommandResult {
221
+ spinner,
222
+ symbol: succeed_symbol(),
223
+ msg: succeed_message("Your app has been deployed successfully."),
224
+ })
225
+ }
226
Err(e) => {
189
- //println!("Failed to push to remote: {:#?}", e);
227
+ println!("Failed to push to remote: {:#?}", e);
228
spinner.stop_and_persist("😩", e.to_string());
191
- return Ok(CommandResult {
229
+ Ok(CommandResult {
230
spinner,
193
- symbol: "😩".to_owned(),
194
- msg: e.to_string(),
195
- });
231
+ symbol: fail_symbol(),
232
+ msg: fail_message(&e.to_string()),
233
+ })
234
}
235
};
198
-
199
- Ok(CommandResult {
200
- spinner,
201
- symbol: "🚀".to_owned(),
202
- msg: "Your app has been deployed successfully.".to_owned(),
203
- })
236
}
crates/cli/src/deploy/smb_config.rs
renamed
+2
@@ -11,6 +11,8 @@ pub(crate) async fn check_config() -> Result<String> {
11
style("Checking config...").green().bold().to_string(),
12
);
13
14
+ // Check .smb directory
15
+
16
// Get .smb/config.toml file path in the current directory
17
let config_path = Path::new(".smb/config.toml");
18
if !config_path.exists() {