2 files changed
+32
-11
smbcloud-cli/src/account/lib.rs
+3
-1
@@ -20,6 +20,8 @@ use std::{
20
};
21
use url_builder::URLBuilder;
22
23
+use crate::ui::fail_message;
24
+
25
pub async fn authorize_github(env: &Environment) -> Result<SmbAuthorization> {
26
// Spin up a simple localhost server to listen for the GitHub OAuth callback
27
// setup_oauth_callback_server();
@@ -244,7 +246,7 @@ pub async fn protected_request(env: Environment) -> Result<()> {
246
// Check if token file exists
247
if smb_token_file_path(env).is_none() {
248
return Err(anyhow!(
247
- "Please authorize your account first with `smb account login` command."
249
+ fail_message("Please authorize your account first with `smb account login` command.")
250
));
251
}
252
Ok(())
smbcloud-cli/src/project/init.rs
+29
-10
@@ -1,4 +1,8 @@
1
-use crate::{account::lib::protected_request, cli::CommandResult, ui::{succeed_message, succeed_symbol}};
1
+use crate::{
2
+ account::lib::protected_request,
3
+ cli::CommandResult,
4
+ ui::{fail_message, succeed_message, succeed_symbol},
5
+};
6
use anyhow::{anyhow, Result};
7
use console::style;
8
use dialoguer::{theme::ColorfulTheme, Input};
@@ -16,8 +20,7 @@ pub async fn process_project_init(env: Environment) -> Result<CommandResult> {
20
{
21
Ok(project_name) => project_name,
22
Err(_) => {
19
- let error = anyhow!("Invalid project name.");
20
- return Err(error);
23
+ return Err(anyhow!(fail_message("Invalid project name.")));
24
}
25
};
26
let description = match Input::<String>::with_theme(&ColorfulTheme::default())
@@ -26,11 +29,12 @@ pub async fn process_project_init(env: Environment) -> Result<CommandResult> {
29
{
30
Ok(description) => description,
31
Err(_) => {
29
- let error = anyhow!("Invalid description.");
30
- return Err(error);
32
+ return Err(anyhow!(fail_message("Invalid description")));
33
}
34
};
35
36
+ setup_smb_folder(&project_name, &description).await?;
37
+
38
let spinner = Spinner::new(
39
spinners::Spinners::SimpleDotsScrolling,
40
style("Creating a project...").green().bold().to_string(),
@@ -52,11 +56,26 @@ pub async fn process_project_init(env: Environment) -> Result<CommandResult> {
56
}),
57
Err(e) => {
58
println!("Error: {e:#?}");
55
- Ok(CommandResult {
56
- spinner,
57
- symbol: succeed_symbol(),
58
- msg: format!("Failed to create a project {project_name}."),
59
- })
59
+ Err(anyhow!(fail_message("Failed to create project.")))
60
}
61
}
62
}
63
+
64
+async fn setup_smb_folder(name: &str, description: &str) -> Result<()> {
65
+ // Create .smb folder in the current directory
66
+ std::fs::create_dir(".smb")?;
67
+ // Create config.toml file in the .smb folder
68
+ let repository_name = name.to_lowercase().replace(" ", "");
69
+ std::fs::write(
70
+ ".smb/config.toml",
71
+ format!(
72
+ r#"
73
+name = "{name}"
74
+description = "{description}"
75
+[repository]
76
+name = "{repository_name}"
77
+"#,
78
+ ),
79
+ )?;
80
+ Ok(())
81
+}