5 files changed
+44
-22
smbpndk-cli/src/account/cli.rs
new
+13
@@ -0,0 +1,13 @@
1
+use clap::Subcommand;
2
+
3
+#[derive(Subcommand)]
4
+pub enum Commands {
5
+ #[clap(about = "Create an account. Use your email as your username.")]
6
+ Signup {},
7
+ #[clap(about = "Login to your account. To create an account, use smb signup.")]
8
+ Login {},
9
+ #[clap(about = "Logout all session.")]
10
+ Logout {},
11
+ #[clap(about = "Forgot email? Use this command to reset your password.")]
12
+ Forgot {},
13
+}
smbpndk-cli/src/account/mod.rs
+19
@@ -1,4 +1,23 @@
1
+pub mod cli;
2
pub mod forgot;
3
pub mod login;
4
pub mod model;
5
pub mod signup;
6
+
7
+use self::{
8
+ cli::Commands,
9
+ forgot::process_forgot,
10
+ login::{process_login, process_logout},
11
+ signup::process_signup,
12
+};
13
+use crate::cli::CommandResult;
14
+use anyhow::Result;
15
+
16
+pub async fn process_account(commands: Commands) -> Result<CommandResult> {
17
+ match commands {
18
+ Commands::Signup {} => process_signup().await,
19
+ Commands::Login {} => process_login().await,
20
+ Commands::Logout {} => process_logout().await,
21
+ Commands::Forgot {} => process_forgot().await,
22
+ }
23
+}
smbpndk-cli/src/cli/mod.rs
+7
-10
@@ -1,7 +1,7 @@
1
use clap::{Parser, Subcommand};
2
use spinners::Spinner;
3
4
-use crate::{auth_app, project};
4
+use crate::{account, auth_app, project};
5
6
pub struct CommandResult {
7
pub spinner: Spinner,
@@ -22,17 +22,14 @@ pub struct Cli {
22
23
#[derive(Subcommand)]
24
pub enum Commands {
25
- #[clap(about = "Create an account. Use your email as your username.")]
26
- Signup {},
27
- #[clap(about = "Login to your account. To create an account, use smb signup.")]
28
- Login {},
29
- #[clap(about = "Logout all session.")]
30
- Logout {},
31
- #[clap(about = "Forgot email? Use this command to reset your password.")]
32
- Forgot {},
25
+ #[clap(about = "Manage your account.")]
26
+ Account {
27
+ #[clap(subcommand)]
28
+ command: account::cli::Commands,
29
+ },
30
31
#[clap(about = "Manage your projects. Add, delete, edit. Need authentication.")]
35
- Projects {
32
+ Project {
33
#[clap(subcommand)]
34
command: project::cli::Commands,
35
},
smbpndk-cli/src/main.rs
+4
-11
@@ -5,14 +5,10 @@ use dotenv::dotenv;
5
use std::{fs::OpenOptions, path::PathBuf, str::FromStr};
6
7
use smbpndk_cli::{
8
- account::{
9
- forgot::process_forgot,
10
- login::{process_login, process_logout},
11
- signup::process_signup,
12
- },
8
+ account::process_account,
9
auth_app::process_auth_app,
10
cli::{Cli, CommandResult, Commands},
15
- project::process_projects,
11
+ project::process_project,
12
};
13
14
use tracing::subscriber::set_global_default;
@@ -86,11 +82,8 @@ async fn run() -> Result<CommandResult> {
82
}
83
84
match cli.command {
89
- Commands::Login {} => process_login().await,
90
- Commands::Logout {} => process_logout().await,
91
- Commands::Signup {} => process_signup().await,
92
- Commands::Forgot {} => process_forgot().await,
93
- Commands::Projects { command } => process_projects(command).await,
85
+ Commands::Account { command } => process_account(command).await,
86
+ Commands::Project { command } => process_project(command).await,
87
Commands::AuthApp { command } => process_auth_app(command).await,
88
}
89
}
smbpndk-cli/src/project/mod.rs
+1
-1
@@ -13,7 +13,7 @@ use crate::cli::CommandResult;
13
14
use self::cli::Commands;
15
16
-pub async fn process_projects(commands: Commands) -> Result<CommandResult> {
16
+pub async fn process_project(commands: Commands) -> Result<CommandResult> {
17
match commands {
18
Commands::New {} => {
19
let project_name = Input::<String>::with_theme(&ColorfulTheme::default())