@smbcloud / cli / commits / 8c53578

Add dialoguer

Seto Elkahfi committed Feb 28, 2023 at 21:57 UTC 8c535780b326915ba3e5eeab0f25ee4f1493dbbb
4 files changed +40 -9
Cargo.lock
+25
@@ -128,6 +128,18 @@ version = "0.8.3"
128 source = "registry+https://github.com/rust-lang/crates.io-index"
129 checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
130
131 +[[package]]
132 +name = "dialoguer"
133 +version = "0.10.3"
134 +source = "registry+https://github.com/rust-lang/crates.io-index"
135 +checksum = "af3c796f3b0b408d9fd581611b47fa850821fcb84aa640b83a3c1a5be2d691f2"
136 +dependencies = [
137 + "console",
138 + "shell-words",
139 + "tempfile",
140 + "zeroize",
141 +]
142 +
143 [[package]]
144 name = "encode_unicode"
145 version = "0.3.6"
@@ -910,6 +922,12 @@ dependencies = [
922 "lazy_static",
923 ]
924
925 +[[package]]
926 +name = "shell-words"
927 +version = "1.1.0"
928 +source = "registry+https://github.com/rust-lang/crates.io-index"
929 +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
930 +
931 [[package]]
932 name = "signal-hook-registry"
933 version = "1.4.1"
@@ -941,6 +959,7 @@ dependencies = [
959 "anyhow",
960 "clap",
961 "console",
962 + "dialoguer",
963 "home",
964 "reqwest",
965 "serde",
@@ -1469,3 +1488,9 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d"
1488 dependencies = [
1489 "winapi",
1490 ]
1491 +
1492 +[[package]]
1493 +name = "zeroize"
1494 +version = "1.5.7"
1495 +source = "registry+https://github.com/rust-lang/crates.io-index"
1496 +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f"
Cargo.toml
+1
@@ -17,6 +17,7 @@ path = "src/main.rs"
17 anyhow = "1.0.58"
18 clap = { version = "4.1.6", features = ["derive"] }
19 console = "0.15.0"
20 +dialoguer = "0.10.3"
21 home = "0.5.4"
22 reqwest = { version = "0.11", features = ["json"] }
23 serde = { version = "1", features = ["derive"] }
src/cli/mod.rs
+2 -7
@@ -13,11 +13,6 @@ pub struct Cli {
13
14 #[derive(Subcommand)]
15 pub enum Commands {
16 - #[clap(about = "Create a new project")]
17 - Login {
18 - #[clap(short, long)]
19 - username: String,
20 - #[clap(short, long)]
21 - password: String,
22 - },
16 + #[clap(about = "Login to your account. To create an account, visit https://smbpndk.com")]
17 + Login {},
18 }
src/main.rs
+12 -2
@@ -3,6 +3,7 @@ use std::{fs::OpenOptions, path::PathBuf, str::FromStr};
3 use anyhow::{anyhow, Result};
4 use clap::Parser;
5 use console::style;
6 +use dialoguer::{theme::ColorfulTheme, Input, Password};
7 use smbpndk_cli::{
8 cli::{Cli, Commands},
9 constants::{ERROR_EMOJI, OK_EMOJI},
@@ -72,8 +73,17 @@ async fn run() -> Result<()> {
73 }
74
75 match cli.command {
75 - Commands::Login { username, password } => {
76 - println!("Login: {}, {}", username, password);
76 + Commands::Login {} => {
77 + println!("Provide your login credentials.");
78 + let username = Input::<String>::with_theme(&ColorfulTheme::default())
79 + .with_prompt("Username")
80 + .interact()
81 + .unwrap();
82 + let password = Password::with_theme(&ColorfulTheme::default())
83 + .with_prompt("Password")
84 + .interact()
85 + .unwrap();
86 +
87 process_login(LoginArgs { username, password }).await?;
88 }
89 }