Skip to content

Commit dfc8227

Browse files
improvements during testing presentation scenario
1 parent 10d8ad9 commit dfc8227

15 files changed

Lines changed: 83 additions & 190 deletions

File tree

cli/src/commands/config/subcommands/get.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,14 @@ impl MevaCommand for ConfigGetCommand {
7070
let default = matches.get_one::<String>(Self::ARG_DEFAULT);
7171

7272
let config_handler = container.config_handler().into_diagnostic()?;
73-
let interceptor = container.plugins_interceptor().into_diagnostic()?;
7473

7574
let request = GetRequest {
7675
location,
7776
key: key.clone(),
7877
default: default.cloned(),
7978
};
8079

81-
let response = config_handler
82-
.handle_get(request, &interceptor)
83-
.into_diagnostic()?;
80+
let response = config_handler.handle_get(request).into_diagnostic()?;
8481

8582
println!("{}", response.value);
8683

cli/src/commands/config/subcommands/list.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,10 @@ impl MevaCommand for ConfigListCommand {
4848
let location = matches.get_config_location();
4949

5050
let config_handler = container.config_handler().into_diagnostic()?;
51-
let interceptor = container.plugins_interceptor().into_diagnostic()?;
5251

5352
let request = ListRequest { location };
5453

55-
let response = config_handler
56-
.handle_list(request, &interceptor)
57-
.into_diagnostic()?;
54+
let response = config_handler.handle_list(request).into_diagnostic()?;
5855

5956
if response.key_values.is_empty() {
6057
println!(

cli/src/commands/ignore/subcommands/add.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use engine::{
88
};
99
use globset::Glob;
1010
use miette::IntoDiagnostic;
11+
use owo_colors::OwoColorize;
12+
use shared::PathToString;
1113

1214
use crate::{
1315
commands::MevaCommand,
@@ -58,8 +60,8 @@ impl MevaCommand for IgnoreAddCommand {
5860

5961
println!(
6062
"Pattern '{}' appended to {}",
61-
pattern,
62-
result_path.to_string_lossy()
63+
pattern.green(),
64+
result_path.to_utf8_string().cyan()
6365
);
6466

6567
Ok(())

cli/src/commands/plugins/subcommands/list.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use async_trait::async_trait;
2-
use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command};
2+
use clap::{Arg, ArgAction, ArgGroup, ArgMatches, Command, builder::PossibleValuesParser};
33
use engine::{
44
EngineContainer,
55
engine_container::MevaContainer,
66
handlers::plugins::{ListRequest, PluginsOperations},
77
};
88
use miette::IntoDiagnostic;
99
use plugins::{CommandType, EventType, ScopeType};
10+
use strum::VariantNames;
1011

1112
use crate::{commands::MevaCommand, extensions::WithScope};
1213

@@ -46,13 +47,15 @@ impl MevaCommand for PluginsListCommand {
4647
.index(1)
4748
.required(true)
4849
.value_name("COMMAND")
50+
.value_parser(PossibleValuesParser::new(CommandType::VARIANTS))
4951
.help("Filter plugins by associated command"),
5052
)
5153
.arg(
5254
Arg::new(Self::ARG_EVENT)
5355
.index(2)
5456
.required(true)
5557
.value_name("EVENT")
58+
.value_parser(PossibleValuesParser::new(EventType::VARIANTS))
5659
.help("Filter plugins by event"),
5760
)
5861
.with_scope_arg("Scope of the plugin")

engine/src/handlers/commit/handlers.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,22 @@ impl CommitHandler {
8181
) -> EngineResult<Response> {
8282
match self.should_execute(&request)? {
8383
false => Err(CommitError::NothingToCommit.into()),
84-
true => interceptor.intercept_with_plugins(
85-
CommandType::Commit,
86-
None,
87-
request,
88-
self,
89-
|req| self.commit(req),
90-
),
84+
true => {
85+
let mut request = request;
86+
if request.author.is_none() {
87+
request.author = Some(Person {
88+
name: self.get_user_name()?,
89+
email: self.get_user_email()?,
90+
});
91+
}
92+
interceptor.intercept_with_plugins(
93+
CommandType::Commit,
94+
None,
95+
request,
96+
self,
97+
|req| self.commit(req),
98+
)
99+
}
91100
}
92101
}
93102

@@ -123,7 +132,7 @@ impl CommitHandler {
123132
}
124133

125134
/// Retrieves the configured username from the repository settings.
126-
fn get_username(&self) -> EngineResult<String> {
135+
fn get_user_name(&self) -> EngineResult<String> {
127136
self.config_loader
128137
.get("user.name", Some(&String::default()))
129138
}
@@ -188,8 +197,9 @@ impl CommitOperations for CommitHandler {
188197
fn commit(&self, request: Request) -> EngineResult<Response> {
189198
let author = match request.author.clone() {
190199
Some(a) => a,
200+
// should not happen
191201
None => Person {
192-
name: self.get_username()?,
202+
name: self.get_user_name()?,
193203
email: self.get_user_email()?,
194204
},
195205
};

engine/src/handlers/commit/operations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::objects::{MevaCommit, Person};
66
///
77
/// This struct holds input data passed to the commit process,
88
/// including the commit message, author information, and execution flags.
9-
#[derive(Debug, Default)]
9+
#[derive(Debug, Default, Clone)]
1010
pub struct Request {
1111
/// Commit message provided by the user.
1212
pub message: String,

engine/src/handlers/config/handlers.rs

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,8 @@ impl ConfigHandler {
2121
Self { config_loader }
2222
}
2323

24-
pub fn handle_get(
25-
&self,
26-
request: GetRequest,
27-
interceptor: &PluginsInterceptor,
28-
) -> EngineResult<GetResponse> {
29-
interceptor.intercept_with_plugins(CommandType::ConfigGet, None, request, self, |req| {
30-
self.get(req)
31-
})
24+
pub fn handle_get(&self, request: GetRequest) -> EngineResult<GetResponse> {
25+
self.get(request)
3226
}
3327

3428
pub fn handle_set(
@@ -51,14 +45,8 @@ impl ConfigHandler {
5145
})
5246
}
5347

54-
pub fn handle_list(
55-
&self,
56-
request: ListRequest,
57-
interceptor: &PluginsInterceptor,
58-
) -> EngineResult<ListResponse> {
59-
interceptor.intercept_with_plugins(CommandType::ConfigList, None, request, self, |req| {
60-
self.list(req)
61-
})
48+
pub fn handle_list(&self, request: ListRequest) -> EngineResult<ListResponse> {
49+
self.list(request)
6250
}
6351

6452
pub fn handle_create(&self, request: CreateRequest) -> EngineResult<CreateResponse> {
@@ -120,50 +108,6 @@ impl ConfigOperations for ConfigHandler {
120108
}
121109
}
122110

123-
impl PluginsInvocationMapper<GetRequest, GetResponse> for ConfigHandler {
124-
fn request_to_payload(&self, req: &GetRequest) -> EngineResult<InvocationPrePayload> {
125-
Ok(InvocationPrePayload::ConfigGet(ConfigGetPrePayload {
126-
config_file: req.location.get_default_path()?,
127-
key: req.key.clone(),
128-
default: req.default.clone(),
129-
}))
130-
}
131-
132-
fn response_to_payload(&self, res: &GetResponse) -> EngineResult<InvocationPostPayload> {
133-
Ok(InvocationPostPayload::ConfigGet(ConfigGetPostPayload {
134-
key: res.key.clone(),
135-
value: res.value.clone(),
136-
}))
137-
}
138-
139-
fn input_to_request(&self, input: &InvocationInput) -> EngineResult<GetRequest> {
140-
if let Some(InvocationPrePayload::ConfigGet(pre)) = &input.pre_payload {
141-
Ok(GetRequest {
142-
location: ConfigLocation::from_path(&pre.config_file)?,
143-
key: pre.key.clone(),
144-
default: pre.default.clone(),
145-
})
146-
} else {
147-
Err(EngineError::Plugins(PluginError::PrePayload {
148-
payload: input.pre_payload.clone(),
149-
}))
150-
}
151-
}
152-
153-
fn input_to_response(&self, input: &InvocationInput) -> EngineResult<GetResponse> {
154-
if let Some(InvocationPostPayload::ConfigGet(post)) = &input.post_payload {
155-
Ok(GetResponse {
156-
key: post.key.clone(),
157-
value: post.value.clone(),
158-
})
159-
} else {
160-
Err(EngineError::Plugins(PluginError::PostPayload {
161-
payload: input.post_payload.clone(),
162-
}))
163-
}
164-
}
165-
}
166-
167111
impl PluginsInvocationMapper<SetRequest, SetResponse> for ConfigHandler {
168112
fn request_to_payload(&self, req: &SetRequest) -> EngineResult<InvocationPrePayload> {
169113
Ok(InvocationPrePayload::ConfigSet(ConfigSetPrePayload {
@@ -195,7 +139,7 @@ impl PluginsInvocationMapper<SetRequest, SetResponse> for ConfigHandler {
195139
}
196140

197141
fn input_to_response(&self, input: &InvocationInput) -> EngineResult<SetResponse> {
198-
if let Some(InvocationPostPayload::ConfigGet(post)) = &input.post_payload {
142+
if let Some(InvocationPostPayload::ConfigSet(post)) = &input.post_payload {
199143
Ok(SetResponse {
200144
key: post.key.clone(),
201145
value: post.value.clone(),
@@ -247,41 +191,3 @@ impl PluginsInvocationMapper<UnsetRequest, UnsetResponse> for ConfigHandler {
247191
}
248192
}
249193
}
250-
251-
impl PluginsInvocationMapper<ListRequest, ListResponse> for ConfigHandler {
252-
fn request_to_payload(&self, req: &ListRequest) -> EngineResult<InvocationPrePayload> {
253-
Ok(InvocationPrePayload::ConfigList(ConfigListPrePayload {
254-
config_file: req.location.get_default_path()?,
255-
}))
256-
}
257-
258-
fn response_to_payload(&self, res: &ListResponse) -> EngineResult<InvocationPostPayload> {
259-
Ok(InvocationPostPayload::ConfigList(ConfigListPostPayload {
260-
key_values: res.key_values.clone(),
261-
}))
262-
}
263-
264-
fn input_to_request(&self, input: &InvocationInput) -> EngineResult<ListRequest> {
265-
if let Some(InvocationPrePayload::ConfigList(pre)) = &input.pre_payload {
266-
Ok(ListRequest {
267-
location: ConfigLocation::from_path(&pre.config_file)?,
268-
})
269-
} else {
270-
Err(EngineError::Plugins(PluginError::PrePayload {
271-
payload: input.pre_payload.clone(),
272-
}))
273-
}
274-
}
275-
276-
fn input_to_response(&self, input: &InvocationInput) -> EngineResult<ListResponse> {
277-
if let Some(InvocationPostPayload::ConfigList(post)) = &input.post_payload {
278-
Ok(ListResponse {
279-
key_values: post.key_values.clone(),
280-
})
281-
} else {
282-
Err(EngineError::Plugins(PluginError::PostPayload {
283-
payload: input.post_payload.clone(),
284-
}))
285-
}
286-
}
287-
}

engine/src/handlers/ls_files/models/ls_files_entry.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Display for LsFilesEntry {
2626
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
2727
match self {
2828
LsFilesEntry::Path { path } => {
29-
write!(f, "{}", path.green())
29+
write!(f, "{}", path.cyan())
3030
}
3131
LsFilesEntry::Entry {
3232
mode,
@@ -39,8 +39,8 @@ impl Display for LsFilesEntry {
3939
"{} {} {} {}",
4040
format!("{mode:o}").dimmed(),
4141
object.yellow(),
42-
stage.dimmed(),
43-
path.green()
42+
stage.green(),
43+
path.cyan()
4444
)
4545
}
4646
}

engine/src/handlers/ls_tree/models/ls_tree_entry.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use std::fmt::Display;
22

3+
use owo_colors::OwoColorize;
4+
use shared::PathToString;
5+
36
use super::display_mode::DisplayMode;
47

58
use crate::objects::ObjectEntry;
@@ -21,15 +24,15 @@ impl Display for LsTreeEntry {
2124

2225
match self.display_mode {
2326
DisplayMode::NameOnly => {
24-
write!(f, "{}", entry.path.display())
27+
write!(f, "{}", entry.path.to_utf8_string().cyan())
2528
}
2629
DisplayMode::Normal => {
2730
write!(
2831
f,
2932
"{} {} {}",
30-
entry.entry_type,
31-
entry.hash,
32-
entry.path.display()
33+
entry.entry_type.dimmed(),
34+
entry.hash.yellow(),
35+
entry.path.to_utf8_string().cyan()
3336
)
3437
}
3538
DisplayMode::Long => {
@@ -40,10 +43,10 @@ impl Display for LsTreeEntry {
4043
write!(
4144
f,
4245
"{} {} {:>8} {}",
43-
entry.entry_type,
44-
entry.hash,
45-
size_str,
46-
entry.path.display(),
46+
entry.entry_type.dimmed(),
47+
entry.hash.yellow(),
48+
size_str.green(),
49+
entry.path.to_utf8_string().cyan(),
4750
)
4851
}
4952
}

engine/src/handlers/status/models/branch_info.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::fmt::Display;
22

3+
use owo_colors::OwoColorize;
4+
35
/// Represents information about the current branch and HEAD state.
46
#[derive(Debug, Clone, PartialEq, Eq)]
57
pub struct BranchInfo {
@@ -29,24 +31,32 @@ impl Display for BranchInfo {
2931
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
3032
if self.is_detached {
3133
match &self.head {
32-
Some(oid) => writeln!(f, "HEAD (detached at {oid})")?,
34+
Some(oid) => writeln!(f, "HEAD (detached at {})", oid.yellow())?,
3335
None => writeln!(f, "HEAD (detached)")?,
3436
}
3537
} else if let Some(head) = &self.head {
3638
match &self.upstream {
3739
Some(up) if self.ahead == 0 && self.behind == 0 => {
38-
writeln!(f, "On branch {head} (up to date with {up})")
40+
writeln!(
41+
f,
42+
"On branch {} (up to date with {})",
43+
head.bold().cyan(),
44+
up.cyan()
45+
)
3946
}
4047
Some(up) => writeln!(
4148
f,
42-
"On branch {head} ({} ahead, {} behind of {})",
43-
self.ahead, self.behind, up
49+
"On branch {} ({} ahead, {} behind of {})",
50+
head.bold().cyan(),
51+
self.ahead.green(),
52+
self.behind.red(),
53+
up.cyan()
4454
),
45-
None => writeln!(f, "On branch {head}"),
55+
None => writeln!(f, "On branch {}", head.bold().cyan()),
4656
}?;
4757
if !self.has_commits {
4858
// This is a new/orphan branch with no commit history
49-
writeln!(f, "\nNo commits yet")?;
59+
writeln!(f, "\n{}", "No commits yet".yellow())?;
5060
return writeln!(f);
5161
}
5262
} else {

0 commit comments

Comments
 (0)