@smbcloud / cli / commits / cea0f91

Cleanup main.rs

Seto Elkahfi committed Apr 10, 2023 at 10:20 UTC cea0f91796fd76d54a87aff2c896711378e490c2
4 files changed +31 -28
src/account/forgot/mod.rs
+1 -1
@@ -17,7 +17,7 @@ struct Email {
17 email: String,
18 }
19
20 -pub async fn process() -> Result<CommandResult> {
20 +pub async fn process_forgot() -> Result<CommandResult> {
21 println!("Provide your login credentials.");
22 let email = Input::<String>::with_theme(&ColorfulTheme::default())
23 .with_prompt("Email")
src/account/signup/process.rs
+21 -4
@@ -21,6 +21,8 @@ use crate::{
21 debug,
22 util::CommandResult,
23 };
24 +
25 +use super::SignupMethod;
26 pub struct SignupArgs {
27 pub username: String,
28 pub password: String,
@@ -36,7 +38,22 @@ struct SignupResult {
38 data: Option<Data>,
39 }
40
39 -pub async fn signup_with_email(email: Option<String>) -> Result<CommandResult> {
41 +pub async fn process_signup() -> Result<CommandResult> {
42 + let signup_methods = vec![SignupMethod::Email, SignupMethod::GitHub];
43 + let selection = Select::with_theme(&ColorfulTheme::default())
44 + .items(&signup_methods)
45 + .default(0)
46 + .interact_on_opt(&Term::stderr())
47 + .map(|i| signup_methods[i.unwrap()])
48 + .unwrap();
49 +
50 + match selection {
51 + SignupMethod::Email => signup_with_email(None).await,
52 + SignupMethod::GitHub => signup_with_github().await,
53 + }
54 +}
55 +
56 +async fn signup_with_email(email: Option<String>) -> Result<CommandResult> {
57 let email = if let Some(email) = email {
58 email
59 } else {
@@ -73,7 +90,7 @@ pub async fn signup_with_email(email: Option<String>) -> Result<CommandResult> {
90 style("Signing up...").green().bold().to_string(),
91 );
92
76 - match process_signup(SignupArgs {
93 + match do_signup(SignupArgs {
94 username: email,
95 password,
96 })
@@ -92,7 +109,7 @@ pub async fn signup_with_email(email: Option<String>) -> Result<CommandResult> {
109 }
110 }
111
95 -pub async fn signup_with_github() -> Result<CommandResult> {
112 +async fn signup_with_github() -> Result<CommandResult> {
113 // Spin up a simple localhost server to listen for the GitHub OAuth callback
114 // setup_oauth_callback_server();
115 // Open the GitHub OAuth URL in the user's browser
@@ -331,7 +348,7 @@ fn build_github_access_data_url() -> String {
348 url_builder.build()
349 }
350
334 -async fn process_signup(args: SignupArgs) -> Result<()> {
351 +async fn do_signup(args: SignupArgs) -> Result<()> {
352 let signup_params = SignupParams {
353 user: User {
354 email: args.username,
src/main.rs
+8 -22
@@ -1,18 +1,17 @@
1 use anyhow::{anyhow, Result};
2 use clap::Parser;
3 -use console::{style, Term};
4 -use dialoguer::{theme::ColorfulTheme, Select};
3 +use console::style;
4 use dotenv::dotenv;
5 use std::{fs::OpenOptions, path::PathBuf, str::FromStr};
6
7 use smbpndk_cli::{
8 account::{
10 - self,
11 - login::{process_login, process_logout, LoginArgs},
12 - signup::{signup_with_email, signup_with_github, SignupMethod},
9 + forgot::process_forgot,
10 + login::{process_login, process_logout},
11 + signup::process_signup,
12 },
13 cli::{Cli, Commands},
15 - projects,
14 + projects::process_projects,
15 util::CommandResult,
16 };
17
@@ -89,21 +88,8 @@ async fn run() -> Result<CommandResult> {
88 match cli.command {
89 Commands::Login {} => process_login().await,
90 Commands::Logout {} => process_logout().await,
92 - Commands::Signup {} => {
93 - let signup_methods = vec![SignupMethod::Email, SignupMethod::GitHub];
94 - let selection = Select::with_theme(&ColorfulTheme::default())
95 - .items(&signup_methods)
96 - .default(0)
97 - .interact_on_opt(&Term::stderr())
98 - .map(|i| signup_methods[i.unwrap()])
99 - .unwrap();
100 -
101 - match selection {
102 - SignupMethod::Email => signup_with_email(None).await,
103 - SignupMethod::GitHub => signup_with_github().await,
104 - }
105 - }
106 - Commands::Forgot {} => account::forgot::process().await,
107 - Commands::Projects { command } => projects::process(command).await,
91 + Commands::Signup {} => process_signup().await,
92 + Commands::Forgot {} => process_forgot().await,
93 + Commands::Projects { command } => process_projects(command).await,
94 }
95 }
src/projects/mod.rs
+1 -1
@@ -41,7 +41,7 @@ pub enum Commands {
41 },
42 }
43
44 -pub async fn process(commands: Commands) -> Result<CommandResult> {
44 +pub async fn process_projects(commands: Commands) -> Result<CommandResult> {
45 match commands {
46 Commands::New {} => {
47 let project_name = Input::<String>::with_theme(&ColorfulTheme::default())