2 files changed
+30
-28
crates/cli/src/project/mod.rs
+29
-27
@@ -2,9 +2,11 @@ pub mod cli;
2
pub mod init;
3
4
use self::cli::Commands;
5
-use crate::cli::CommandResult;
5
+use crate::{
6
+ cli::CommandResult,
7
+ ui::{fail_message, fail_symbol, succeed_message, succeed_symbol},
8
+};
9
use anyhow::{anyhow, Result};
7
-use console::style;
10
use dialoguer::{theme::ColorfulTheme, Input};
11
use init::process_project_init;
12
use log::debug;
@@ -20,25 +22,25 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
22
Commands::List {} => {
23
let mut spinner = Spinner::new(
24
spinners::Spinners::SimpleDotsScrolling,
23
- style("Loading...").green().bold().to_string(),
25
+ succeed_message("Loading"),
26
);
27
28
// Get all
29
match get_all(env).await {
30
Ok(projects) => {
29
- spinner.stop_and_persist("✅", "Loaded.".to_owned());
31
+ spinner.stop_and_persist(&succeed_symbol(), succeed_message("Loaded."));
32
let msg = if projects.is_empty() {
31
- "No projects found.".to_owned()
33
+ succeed_message("No projects found.")
34
} else {
33
- "Showing all projects.".to_owned()
35
+ succeed_message("Showing all projects.")
36
};
37
show_projects(projects);
38
Ok(CommandResult {
39
spinner: Spinner::new(
40
spinners::Spinners::SimpleDotsScrolling,
39
- style("Loading...").green().bold().to_string(),
41
+ succeed_message("Loading"),
42
),
41
- symbol: "✅".to_owned(),
43
+ symbol: succeed_symbol(),
44
msg,
45
})
46
}
@@ -46,8 +48,8 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
48
println!("Error: {e:#?}");
49
Ok(CommandResult {
50
spinner,
49
- symbol: "😩".to_owned(),
50
- msg: "Failed to get all projects.".to_owned(),
51
+ symbol: fail_symbol(),
52
+ msg: fail_message("Failed to get all projects."),
53
})
54
}
55
}
@@ -55,25 +57,25 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
57
Commands::Show { id } => {
58
let mut spinner = Spinner::new(
59
spinners::Spinners::SimpleDotsScrolling,
58
- style("Loading...").green().bold().to_string(),
60
+ succeed_message("Loading"),
61
);
62
// Get Detail
63
match get_project(env, id).await {
64
Ok(project) => {
63
- spinner.stop_and_persist("✅", "Loaded.".to_owned());
64
- let message = format!("Showing project {}.", &project.name);
65
+ spinner.stop_and_persist(&succeed_symbol(), succeed_message("Loaded."));
66
+ let message = succeed_message(&format!("Showing project {}.", &project.name));
67
show_projects(vec![project]);
68
Ok(CommandResult {
69
spinner: Spinner::new(
70
spinners::Spinners::SimpleDotsScrolling,
69
- style("Loading...").green().bold().to_string(),
71
+ succeed_message("Loading"),
72
),
71
- symbol: "✅".to_owned(),
73
+ symbol: succeed_symbol(),
74
msg: message,
75
})
76
}
77
Err(e) => {
76
- spinner.stop_and_persist("😩", "Failed.".to_string());
78
+ spinner.stop_and_persist(&fail_symbol(), fail_message("Failed."));
79
Err(anyhow!("{e}"))
80
}
81
}
@@ -86,30 +88,30 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
88
89
let mut spinner = Spinner::new(
90
spinners::Spinners::SimpleDotsScrolling,
89
- style("Deleting project...").green().bold().to_string(),
91
+ succeed_message("Deleting project"),
92
);
93
94
if confirmation != "y" {
95
return Ok(CommandResult {
96
spinner,
95
- symbol: "✅".to_owned(),
96
- msg: "Cancelled.".to_string(),
97
+ symbol: succeed_symbol(),
98
+ msg: succeed_message("Cancelled."),
99
});
100
}
101
match delete_project(env, id).await {
102
Ok(_) => {
101
- spinner.stop_and_persist("✅", "Done.".to_string());
103
+ spinner.stop_and_persist(&succeed_symbol(), succeed_message("Done."));
104
Ok(CommandResult {
105
spinner: Spinner::new(
106
spinners::Spinners::SimpleDotsScrolling,
105
- style("Loading...").green().bold().to_string(),
107
+ succeed_message("Loading"),
108
),
107
- symbol: "✅".to_owned(),
108
- msg: "Project has been deleted.".to_string(),
109
+ symbol: succeed_symbol(),
110
+ msg: succeed_message("Project has been deleted."),
111
})
112
}
113
Err(e) => {
112
- spinner.stop_and_persist("😩", "Failed.".to_string());
114
+ spinner.stop_and_persist(&fail_symbol(), fail_message("Failed."));
115
Err(anyhow!("{e}"))
116
}
117
}
@@ -124,7 +126,7 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
126
127
let spinner = Spinner::new(
128
spinners::Spinners::SimpleDotsScrolling,
127
- style("Loading...").green().bold().to_string(),
129
+ succeed_message("Loading"),
130
);
131
match home::home_dir() {
132
Some(path) => {
@@ -139,8 +141,8 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
141
142
Ok(CommandResult {
143
spinner,
142
- symbol: "✅".to_owned(),
143
- msg: "Use project successful.".to_string(),
144
+ symbol: succeed_symbol(),
145
+ msg: succeed_message("Use project successful."),
146
})
147
}
148
None => {
crates/cli/src/ui/mod.rs
+1
-1
@@ -9,7 +9,7 @@ pub fn fail_symbol() -> String {
9
}
10
11
pub fn succeed_message(message: &str) -> String {
12
- style(message).bold().white().to_string()
12
+ style(message).white().to_string()
13
}
14
15
pub fn fail_message(message: &str) -> String {