5 files changed
+85
-7
src/cli/mod.rs
+7
@@ -1,5 +1,7 @@
1
use clap::{Parser, Subcommand};
2
3
+use crate::projects;
4
+
5
#[derive(Parser)]
6
#[clap(author, version, about)]
7
pub struct Cli {
@@ -20,4 +22,9 @@ pub enum Commands {
22
about = "Login to your account. To create an account, use smb signup or visit https://smbpndk.com"
23
)]
24
Login {},
25
+ #[clap(about = "Manage your projects. Add, delete, edit. Need authentication.")]
26
+ Projects {
27
+ #[clap(subcommand)]
28
+ command: projects::Commands,
29
+ },
30
}
src/lib.rs
+2
-1
@@ -1,4 +1,5 @@
1
pub mod account;
2
pub mod cli;
3
pub mod constants;
4
-mod util;
4
+pub mod projects;
5
+pub mod util;
src/main.rs
+3
-6
@@ -12,6 +12,8 @@ use smbpndk_cli::{
12
},
13
cli::{Cli, Commands},
14
constants::ERROR_EMOJI,
15
+ projects,
16
+ util::CommandResult,
17
};
18
use spinners::Spinner;
19
@@ -61,12 +63,6 @@ async fn main() {
63
}
64
}
65
64
-struct CommandResult {
65
- spinner: Spinner,
66
- symbol: String,
67
- msg: String,
68
-}
69
-
66
async fn run() -> Result<CommandResult> {
67
let cli = Cli::parse();
68
@@ -161,5 +157,6 @@ async fn run() -> Result<CommandResult> {
157
}),
158
}
159
}
160
+ Commands::Projects { command } => projects::process(command),
161
}
162
}
src/projects/mod.rs
new
+65
@@ -0,0 +1,65 @@
1
+use anyhow::Result;
2
+use clap::Subcommand;
3
+use console::style;
4
+use spinners::Spinner;
5
+
6
+use crate::util::CommandResult;
7
+
8
+#[derive(Subcommand)]
9
+pub enum Commands {
10
+ #[clap(about = "Add new project.")]
11
+ New {
12
+ /// Project name
13
+ #[clap(short, long, global = true)]
14
+ name: Option<String>,
15
+ },
16
+
17
+ #[clap(about = "List all your projects.")]
18
+ List {},
19
+
20
+ #[clap(about = "Show detail of a project.")]
21
+ Show {
22
+ /// Project name
23
+ #[clap(short, long, required = true)]
24
+ name: String,
25
+ },
26
+
27
+ #[clap(about = "Delete a project.")]
28
+ Delete {},
29
+}
30
+
31
+pub fn process(commands: Commands) -> Result<CommandResult> {
32
+ let spinner = Spinner::new(
33
+ spinners::Spinners::SimpleDotsScrolling,
34
+ style("Logging in...").green().bold().to_string(),
35
+ );
36
+ match commands {
37
+ Commands::New { name } => {
38
+ let project_name = match name {
39
+ Some(name) => name,
40
+ None => "tempe-goreng".to_owned(),
41
+ };
42
+
43
+ Ok(CommandResult {
44
+ spinner,
45
+ symbol: "✅".to_owned(),
46
+ msg: format!("Creating a project {project_name}."),
47
+ })
48
+ }
49
+ Commands::List {} => Ok(CommandResult {
50
+ spinner,
51
+ symbol: "✅".to_owned(),
52
+ msg: "You are signed up! Check your email to confirm your account.".to_owned(),
53
+ }),
54
+ Commands::Show { name } => Ok(CommandResult {
55
+ spinner,
56
+ symbol: "✅".to_owned(),
57
+ msg: format!("Showing project {name}."),
58
+ }),
59
+ Commands::Delete {} => Ok(CommandResult {
60
+ spinner,
61
+ symbol: "✅".to_owned(),
62
+ msg: "You are signed up! Check your email to confirm your account.".to_owned(),
63
+ }),
64
+ }
65
+}
src/util.rs
+8
@@ -1,3 +1,5 @@
1
+use spinners::Spinner;
2
+
3
#[macro_export]
4
macro_rules! debug {
5
($($e:expr),+) => {
@@ -13,3 +15,9 @@ macro_rules! debug {
15
}
16
};
17
}
18
+
19
+pub struct CommandResult {
20
+ pub spinner: Spinner,
21
+ pub symbol: String,
22
+ pub msg: String,
23
+}