7 files changed
+125
-18
Cargo.lock
+8
@@ -41,6 +41,14 @@ checksum = "224afbd727c3d6e4b90103ece64b8d1b67fbb1973b1046c2281eed3f3803f800"
41
[[package]]
42
name = "app-fun"
43
version = "0.1.0"
44
+dependencies = [
45
+ "anyhow",
46
+ "clap",
47
+ "console",
48
+ "dialoguer",
49
+ "smbpndk-model",
50
+ "spinners",
51
+]
52
53
[[package]]
54
name = "app-oten"
app-fun/Cargo.toml
+6
@@ -5,3 +5,9 @@ edition = "2021"
5
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
6
7
[dependencies]
8
+clap = { version = "4.1.6", features = ["derive"] }
9
+anyhow = "1.0.58"
10
+smbpndk-model = { path = "../smbpndk-model" }
11
+spinners = "4.1.0"
12
+console = "0.15.0"
13
+dialoguer = "0.10.4"
\ No newline at end of file
app-fun/src/cli.rs
new
+30
@@ -0,0 +1,30 @@
1
+use clap::Subcommand;
2
+
3
+#[derive(Subcommand)]
4
+pub enum Commands {
5
+ #[clap(about = "Add new Fun app.")]
6
+ New {},
7
+
8
+ #[clap(about = "List all your Fun apps.")]
9
+ List {},
10
+
11
+ #[clap(about = "Show detail of a Fun app.")]
12
+ Show {
13
+ /// Project Id
14
+ #[clap(short, long, required = true)]
15
+ id: String,
16
+ },
17
+
18
+ #[clap(about = "Delete a Fun app.")]
19
+ Delete {
20
+ /// Project name
21
+ #[clap(short, long, required = true)]
22
+ id: String,
23
+ },
24
+
25
+ #[clap(about = "Use Fun app for current CLI session.")]
26
+ Use {
27
+ #[clap(short, long, required = true)]
28
+ id: String,
29
+ },
30
+}
app-fun/src/handler.rs
new
+74
@@ -0,0 +1,74 @@
1
+use crate::cli::Commands;
2
+use anyhow::Result;
3
+use console::style;
4
+use smbpndk_model::CommandResult;
5
+use spinners::Spinner;
6
+
7
+pub async fn process_fun_app(commands: Commands) -> Result<CommandResult> {
8
+ match commands {
9
+ Commands::New {} => {
10
+ let spinner = Spinner::new(
11
+ spinners::Spinners::SimpleDotsScrolling,
12
+ style("Creating a Fun app...").green().bold().to_string(),
13
+ );
14
+ Ok(CommandResult {
15
+ spinner,
16
+ symbol: "".to_owned(),
17
+ msg: "".to_owned(),
18
+ })
19
+ }
20
+ Commands::List {} => {
21
+ let spinner = Spinner::new(
22
+ spinners::Spinners::SimpleDotsScrolling,
23
+ style("Listing Fun apps...").green().bold().to_string(),
24
+ );
25
+ Ok(CommandResult {
26
+ spinner,
27
+ symbol: "".to_owned(),
28
+ msg: "".to_owned(),
29
+ })
30
+ }
31
+ Commands::Show { id } => {
32
+ let spinner = Spinner::new(
33
+ spinners::Spinners::SimpleDotsScrolling,
34
+ style(format!("Showing Fun app {id}..."))
35
+ .green()
36
+ .bold()
37
+ .to_string(),
38
+ );
39
+ Ok(CommandResult {
40
+ spinner,
41
+ symbol: "".to_owned(),
42
+ msg: "".to_owned(),
43
+ })
44
+ }
45
+ Commands::Delete { id } => {
46
+ let spinner = Spinner::new(
47
+ spinners::Spinners::SimpleDotsScrolling,
48
+ style(format!("Deleting Fun app {id}..."))
49
+ .green()
50
+ .bold()
51
+ .to_string(),
52
+ );
53
+ Ok(CommandResult {
54
+ spinner,
55
+ symbol: "".to_owned(),
56
+ msg: "".to_owned(),
57
+ })
58
+ }
59
+ Commands::Use { id } => {
60
+ let spinner = Spinner::new(
61
+ spinners::Spinners::SimpleDotsScrolling,
62
+ style(format!("Using Fun app {id}..."))
63
+ .green()
64
+ .bold()
65
+ .to_string(),
66
+ );
67
+ Ok(CommandResult {
68
+ spinner,
69
+ symbol: "".to_owned(),
70
+ msg: "".to_owned(),
71
+ })
72
+ }
73
+ }
74
+}
app-fun/src/lib.rs
+2
-14
@@ -1,14 +1,2 @@
1
-pub fn add(left: usize, right: usize) -> usize {
2
- left + right
3
-}
4
-
5
-#[cfg(test)]
6
-mod tests {
7
- use super::*;
8
-
9
- #[test]
10
- fn it_works() {
11
- let result = add(2, 2);
12
- assert_eq!(result, 4);
13
- }
14
-}
1
+pub mod cli;
2
+pub mod handler;
smbpndk-cli/src/cli/mod.rs
+3
-4
@@ -32,11 +32,10 @@ pub enum Commands {
32
command: app_oten::cli::Commands,
33
},
34
// Function
35
- /*
36
- FunApp {
35
+ Fun {
36
#[clap(subcommand)]
38
- command: fun_app::cli::Commands,
39
- }, */
37
+ command: app_fun::cli::Commands,
38
+ },
39
// Package
40
/*
41
PktApp {
smbpndk-cli/src/main.rs
+2
@@ -1,4 +1,5 @@
1
use anyhow::{anyhow, Result};
2
+use app_fun::handler::process_fun_app;
3
use app_oten::{self, handler::process_auth_app};
4
use clap::Parser;
5
use console::style;
@@ -103,5 +104,6 @@ async fn run() -> Result<CommandResult> {
104
Commands::Account { command } => process_account(command).await,
105
Commands::Project { command } => process_project(command).await,
106
Commands::Oten { command } => process_auth_app(command).await,
107
+ Commands::Fun { command } => process_fun_app(command).await,
108
}
109
}