5 files changed
+28
-19
crates/cli/src/cli/mod.rs
+2
-2
@@ -26,8 +26,8 @@ pub struct Cli {
26
#[clap(short, long, global = true)]
27
pub log_level: Option<String>,
28
29
- #[clap(subcommand)]
30
- pub command: Commands,
29
+ #[command(subcommand)]
30
+ pub command: Option<Commands>,
31
}
32
33
#[derive(Subcommand)]
crates/cli/src/deploy/config.rs
+5
-1
@@ -22,7 +22,7 @@ pub(crate) async fn check_config(env: Environment) -> Result<Config, ConfigError
22
// Get .smb/config.toml file path in the current directory
23
let config_path = Path::new(".smb/config.toml");
24
if !config_path.exists() {
25
- spinner.stop_and_persist(&fail_symbol(), fail_message("Invalid config."));
25
+ spinner.stop_and_persist(&succeed_symbol(), succeed_message("Setting up deployment"));
26
setup(env).await?;
27
}
28
@@ -102,4 +102,8 @@ pub enum ConfigError {
102
MissingId,
103
#[error("Could not find project in your list. Make sure you have access to the project.")]
104
ProjectNotFound,
105
+ #[error("Cancel operation.")]
106
+ Cancel,
107
+ #[error("Input error.")]
108
+ InputError,
109
}
crates/cli/src/deploy/setup.rs
+10
-10
@@ -1,4 +1,4 @@
1
-use crate::deploy::config::{Config, ConfigError};
1
+use crate::{deploy::config::{Config, ConfigError}, ui::highlight};
2
use dialoguer::{theme::ColorfulTheme, Confirm, Input, Select};
3
use smbcloud_model::project::{Project, ProjectCreate};
4
use smbcloud_networking::environment::Environment;
@@ -13,17 +13,17 @@ pub async fn setup(env: Environment) -> Result<Config, ConfigError> {
13
.unwrap_or_else(|| ".".to_string());
14
15
let confirm = Confirm::with_theme(&ColorfulTheme::default())
16
- .with_prompt(format!("Setup project in {}? y/n", path_str))
16
+ .with_prompt(format!("Setup project in {}? y/n", highlight(&path_str)))
17
.interact()
18
- .map_err(|_| ConfigError::MissingConfig)?;
18
+ .map_err(|_| ConfigError::InputError)?;
19
20
if !confirm {
21
- return Err(ConfigError::MissingConfig);
21
+ return Err(ConfigError::Cancel);
22
}
23
24
let projects = match get_all(env).await {
25
Ok(x) => x,
26
- Err(_) => return Err(ConfigError::MissingConfig),
26
+ Err(_) => return Err(ConfigError::InputError),
27
};
28
29
let project = if !projects.is_empty() {
@@ -61,7 +61,7 @@ async fn select_project(env: Environment, projects: Vec<Project>) -> Result<Proj
61
let confirm = Confirm::with_theme(&ColorfulTheme::default())
62
.with_prompt("Use existing project? y/n")
63
.interact()
64
- .map_err(|_| ConfigError::MissingConfig)?;
64
+ .map_err(|_| ConfigError::InputError)?;
65
66
if !confirm {
67
return create_new_project(env).await;
@@ -70,7 +70,7 @@ async fn select_project(env: Environment, projects: Vec<Project>) -> Result<Proj
70
.items(&projects)
71
.default(0)
72
.interact()
73
- .map_err(|_| ConfigError::MissingConfig)?;
73
+ .map_err(|_| ConfigError::InputError)?;
74
75
let project = projects[selection].clone();
76
@@ -84,7 +84,7 @@ async fn create_new_project(env: Environment) -> Result<Project, ConfigError> {
84
{
85
Ok(project_name) => project_name,
86
Err(_) => {
87
- return Err(ConfigError::MissingConfig);
87
+ return Err(ConfigError::InputError);
88
}
89
};
90
let repository = match Input::<String>::with_theme(&ColorfulTheme::default())
@@ -94,7 +94,7 @@ async fn create_new_project(env: Environment) -> Result<Project, ConfigError> {
94
{
95
Ok(project_name) => project_name,
96
Err(_) => {
97
- return Err(ConfigError::MissingConfig);
97
+ return Err(ConfigError::InputError);
98
}
99
};
100
let description = match Input::<String>::with_theme(&ColorfulTheme::default())
@@ -103,7 +103,7 @@ async fn create_new_project(env: Environment) -> Result<Project, ConfigError> {
103
{
104
Ok(description) => description,
105
Err(_) => {
106
- return Err(ConfigError::MissingConfig);
106
+ return Err(ConfigError::InputError);
107
}
108
};
109
crates/cli/src/main.rs
+7
-6
@@ -111,11 +111,12 @@ async fn run() -> Result<CommandResult> {
111
}
112
113
match cli.command {
114
- Commands::Init {} => process_project_init(cli.environment).await,
115
- Commands::Deploy {} => process_deploy(cli.environment).await,
116
- Commands::Account { command } => process_account(cli.environment, command).await,
117
- Commands::Login {} => process_login(cli.environment).await,
118
- Commands::Logout {} => process_logout(cli.environment).await,
119
- Commands::Project { command } => process_project(cli.environment, command).await,
114
+ Some(Commands::Init {}) => process_project_init(cli.environment).await,
115
+ Some(Commands::Deploy {}) => process_deploy(cli.environment).await,
116
+ Some(Commands::Account { command }) => process_account(cli.environment, command).await,
117
+ Some(Commands::Login {}) => process_login(cli.environment).await,
118
+ Some(Commands::Logout {}) => process_logout(cli.environment).await,
119
+ Some(Commands::Project { command }) => process_project(cli.environment, command).await,
120
+ None => { process_deploy(cli.environment).await }
121
}
122
}
crates/cli/src/ui/mod.rs
+4
@@ -15,3 +15,7 @@ pub fn succeed_message(message: &str) -> String {
15
pub fn fail_message(message: &str) -> String {
16
style(message).italic().red().to_string()
17
}
18
+
19
+pub fn highlight(string: &str) -> String {
20
+ style(string).italic().green().to_string()
21
+}
\ No newline at end of file