5 files changed
+93
-26
docs/debugging.md
new
+7
@@ -0,0 +1,7 @@
1
+# VSCode Debugging
2
+
3
+To debug the app on VSCode, use [CodeLLDB](https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb) and [cargo debugger](https://github.com/jkelleyrtp/cargo-debugger).
4
+
5
+```bash
6
+$ cargo debugger --manifest-path smbcloud-cli/Cargo.toml -- account signup
7
+```
\ No newline at end of file
smbcloud-cli/src/account/login/process.rs
+80
-20
@@ -41,12 +41,18 @@ pub async fn process_login() -> Result<CommandResult> {
41
}
42
43
let signup_methods = vec![SignupMethod::Email, SignupMethod::GitHub];
44
- let selection = Select::with_theme(&ColorfulTheme::default())
44
+ let selection = match Select::with_theme(&ColorfulTheme::default())
45
.items(&signup_methods)
46
.default(0)
47
.interact_on_opt(&Term::stderr())
48
.map(|i| signup_methods[i.unwrap()])
49
- .unwrap();
49
+ {
50
+ Ok(method) => method,
51
+ Err(e) => {
52
+ let error = anyhow!("No selection made.");
53
+ return Err(error);
54
+ }
55
+ };
56
57
match selection {
58
SignupMethod::Email => login_with_email().await,
@@ -57,10 +63,16 @@ pub async fn process_login() -> Result<CommandResult> {
63
pub async fn process_logout() -> Result<CommandResult> {
64
// Logout if user confirms
65
if let Some(token_path) = smb_token_file_path() {
60
- let confirm = Confirm::with_theme(&ColorfulTheme::default())
66
+ let confirm = match Confirm::with_theme(&ColorfulTheme::default())
67
.with_prompt("Do you want to logout? y/n")
68
.interact()
63
- .unwrap();
69
+ {
70
+ Ok(confirm) => confirm,
71
+ Err(_) => {
72
+ let error = anyhow!("Invalid input.");
73
+ return Err(error);
74
+ }
75
+ };
76
if !confirm {
77
return Ok(CommandResult {
78
spinner: Spinner::new(
@@ -159,10 +171,16 @@ async fn create_new_account(
171
user_email: Option<GithubEmail>,
172
user_info: Option<GithubInfo>,
173
) -> Result<CommandResult> {
162
- let confirm = Confirm::with_theme(&ColorfulTheme::default())
174
+ let confirm = match Confirm::with_theme(&ColorfulTheme::default())
175
.with_prompt("Do you want to create a new account?")
176
.interact()
165
- .unwrap();
177
+ {
178
+ Ok(confirm) => confirm,
179
+ Err(_) => {
180
+ let error = anyhow!("Invalid input.");
181
+ return Err(error);
182
+ }
183
+ };
184
185
// Create account if user confirms
186
if !confirm {
@@ -197,10 +215,16 @@ async fn create_new_account(
215
async fn send_email_verification(user: Option<User>) -> Result<CommandResult> {
216
// Return early if user is null
217
if let Some(user) = user {
200
- let confirm = Confirm::with_theme(&ColorfulTheme::default())
218
+ let confirm = match Confirm::with_theme(&ColorfulTheme::default())
219
.with_prompt("Do you want to send a new verification email?")
220
.interact()
203
- .unwrap();
221
+ {
222
+ Ok(confirm) => confirm,
223
+ Err(_) => {
224
+ let error = anyhow!("Invalid input.");
225
+ return Err(error);
226
+ }
227
+ };
228
229
// Send verification email if user confirms
230
if !confirm {
@@ -252,10 +276,16 @@ async fn resend_email_verification(user: User) -> Result<CommandResult> {
276
}
277
278
async fn connect_github_account(auth: SmbAuthorization) -> Result<CommandResult> {
255
- let confirm = Confirm::with_theme(&ColorfulTheme::default())
279
+ let confirm = match Confirm::with_theme(&ColorfulTheme::default())
280
.with_prompt("Do you want to link your GitHub account?")
281
.interact()
258
- .unwrap();
282
+ {
283
+ Ok(confirm) => confirm,
284
+ Err(_) => {
285
+ let error = anyhow!("Invalid input.");
286
+ return Err(error);
287
+ }
288
+ };
289
290
// Link GitHub account if user confirms
291
if !confirm {
@@ -301,15 +331,27 @@ async fn connect_github_account(auth: SmbAuthorization) -> Result<CommandResult>
331
332
async fn login_with_email() -> Result<CommandResult> {
333
println!("Provide your login credentials.");
304
- let username = Input::<String>::with_theme(&ColorfulTheme::default())
334
+ let username = match Input::<String>::with_theme(&ColorfulTheme::default())
335
.with_prompt("Email")
336
.validate_with(|email: &String| email_validation(email))
337
.interact()
308
- .unwrap();
309
- let password = Password::with_theme(&ColorfulTheme::default())
338
+ {
339
+ Ok(email) => email,
340
+ Err(_) => {
341
+ let error = anyhow!("Invalid email.");
342
+ return Err(error);
343
+ }
344
+ };
345
+ let password = match Password::with_theme(&ColorfulTheme::default())
346
.with_prompt("Password")
347
.interact()
312
- .unwrap();
348
+ {
349
+ Ok(password) => password,
350
+ Err(_) => {
351
+ let error = anyhow!("Invalid password.");
352
+ return Err(error);
353
+ }
354
+ };
355
do_process_login(LoginArgs { username, password }).await
356
}
357
@@ -378,10 +420,16 @@ async fn verify_or_set_password(result: SmbAuthorization) -> Result<CommandResul
420
async fn send_reset_password(user: Option<User>) -> Result<CommandResult> {
421
// Return early if user is null
422
if let Some(user) = user {
381
- let confirm = Confirm::with_theme(&ColorfulTheme::default())
423
+ let confirm = match Confirm::with_theme(&ColorfulTheme::default())
424
.with_prompt("Do you want to reset your password?")
425
.interact()
384
- .unwrap();
426
+ {
427
+ Ok(confirm) => confirm,
428
+ Err(_) => {
429
+ let error = anyhow!("Invalid input.");
430
+ return Err(error);
431
+ }
432
+ };
433
434
// Send verification email if user confirms
435
if !confirm {
@@ -434,15 +482,27 @@ async fn resend_reset_password_instruction(user: User) -> Result<CommandResult>
482
}
483
484
async fn input_reset_password_token() -> Result<CommandResult> {
437
- let token = Input::<String>::with_theme(&ColorfulTheme::default())
485
+ let token = match Input::<String>::with_theme(&ColorfulTheme::default())
486
.with_prompt("Input reset password token")
487
.interact()
440
- .unwrap();
441
- let password = Password::with_theme(&ColorfulTheme::default())
488
+ {
489
+ Ok(token) => token,
490
+ Err(_) => {
491
+ let error = anyhow!("Invalid token.");
492
+ return Err(error);
493
+ }
494
+ };
495
+ let password = match Password::with_theme(&ColorfulTheme::default())
496
.with_prompt("New password.")
497
.with_confirmation("Repeat password.", "Error: the passwords don't match.")
498
.interact()
445
- .unwrap();
499
+ {
500
+ Ok(password) => password,
501
+ Err(_) => {
502
+ let error = anyhow!("Invalid password.");
503
+ return Err(error);
504
+ }
505
+ };
506
507
let spinner = Spinner::new(
508
spinners::Spinners::SimpleDotsScrolling,
smbcloud-cli/src/cli/mod.rs
+2
-2
@@ -33,7 +33,7 @@ pub enum Commands {
33
command: project::cli::Commands,
34
},
35
#[clap(about = "Initialize project. Requires an smbCloud account.")]
36
- Init {
36
+ Init {
37
/// Project name
38
#[clap(short, long, required = false)]
39
name: Option<String>,
@@ -42,5 +42,5 @@ pub enum Commands {
42
description: Option<String>,
43
},
44
#[clap(about = "Deploy project. It will use deploy.sh script in the .smb folder.")]
45
- Deploy { },
45
+ Deploy {},
46
}
smbcloud-cli/src/lib.rs
+1
-1
@@ -1,4 +1,4 @@
1
pub mod account;
2
pub mod cli;
3
-pub mod project;
3
pub mod deploy;
4
+pub mod project;
smbcloud-cli/src/main.rs
+3
-3
@@ -6,8 +6,8 @@ use smbcloud_cli::project::init::process_project_init;
6
use smbcloud_cli::{
7
account::process_account,
8
cli::{Cli, Commands},
9
- project::process_project,
9
deploy::process_deploy,
10
+ project::process_project,
11
};
12
use std::{
13
fs::{create_dir_all, OpenOptions},
@@ -101,7 +101,7 @@ async fn run() -> Result<CommandResult> {
101
match cli.command {
102
Commands::Account { command } => process_account(command).await,
103
Commands::Project { command } => process_project(command).await,
104
- Commands::Init { name, description } => { process_project_init(name, description).await },
105
- Commands::Deploy { } => process_deploy().await,
104
+ Commands::Init { name, description } => process_project_init(name, description).await,
105
+ Commands::Deploy {} => process_deploy().await,
106
}
107
}