4 files changed
+49
smbcloud-cli/src/cli/mod.rs
+9
@@ -32,6 +32,15 @@ pub enum Commands {
32
#[clap(subcommand)]
33
command: project::cli::Commands,
34
},
35
+ #[clap(about = "Initialize project. Requires an smbCloud account.")]
36
+ Init {
37
+ /// Project name
38
+ #[clap(short, long, required = false)]
39
+ name: Option<String>,
40
+ /// Project description
41
+ #[clap(short, long, required = false)]
42
+ description: Option<String>,
43
+ },
44
#[clap(about = "Deploy project. It will use deploy.sh script in the .smb folder.")]
45
Deploy { },
46
}
smbcloud-cli/src/main.rs
+2
@@ -2,6 +2,7 @@ use anyhow::{anyhow, Result};
2
use clap::Parser;
3
use console::style;
4
use smbcloud_cli::cli::CommandResult;
5
+use smbcloud_cli::project::init::process_project_init;
6
use smbcloud_cli::{
7
account::process_account,
8
cli::{Cli, Commands},
@@ -100,6 +101,7 @@ async fn run() -> Result<CommandResult> {
101
match cli.command {
102
Commands::Account { command } => process_account(command).await,
103
Commands::Project { command } => process_project(command).await,
104
+ Commands::Init { name, description } => { process_project_init(name, description).await },
105
Commands::Deploy { } => process_deploy().await,
106
}
107
}
smbcloud-cli/src/project/init.rs
new
+37
@@ -0,0 +1,37 @@
1
+use crate::cli::CommandResult;
2
+use anyhow::Result;
3
+use console::style;
4
+use smbcloud_model::project::ProjectCreate;
5
+use smbcloud_networking_project::create_project;
6
+use spinners::Spinner;
7
+
8
+pub async fn process_project_init(
9
+ name: Option<String>,
10
+ description: Option<String>,
11
+) -> Result<CommandResult> {
12
+ let mut spinner = Spinner::new(
13
+ spinners::Spinners::SimpleDotsScrolling,
14
+ style("Loading...").green().bold().to_string(),
15
+ );
16
+ let name = name.unwrap_or_else(|| "New Project".to_string());
17
+ let description = description.unwrap_or_else(|| "No description".to_string());
18
+ let project = ProjectCreate { name, description };
19
+ match create_project(project).await {
20
+ Ok(p) => {
21
+ spinner.stop_and_persist("✅", "Done.".to_owned());
22
+ Ok(CommandResult {
23
+ spinner,
24
+ symbol: "✅".to_owned(),
25
+ msg: format!("Project {} has been created.", p.name),
26
+ })
27
+ }
28
+ Err(e) => {
29
+ println!("Error: {e:#?}");
30
+ Ok(CommandResult {
31
+ spinner,
32
+ symbol: "😩".to_owned(),
33
+ msg: format!("Failed to initiate a project."),
34
+ })
35
+ }
36
+ }
37
+}
smbcloud-cli/src/project/mod.rs
+1
@@ -1,4 +1,5 @@
1
pub mod cli;
2
+pub mod init;
3
4
use self::cli::Commands;
5
use crate::cli::CommandResult;