Skip to content

Commit

Permalink
Add rule
Browse files Browse the repository at this point in the history
  • Loading branch information
luizvbo committed Apr 29, 2024
1 parent f9972a7 commit 7bd66cf
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
9 changes: 6 additions & 3 deletions src/rules/git_pull.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::{
cli::command::CrabCommand, rules::utils::git::match_rule_with_git_support, shell::Shell,
cli::command::CrabCommand,
rules::{
utils::git::{get_new_command_with_git_support, match_rule_with_git_support},
Rule,
},
shell::Shell,
};

use super::{utils::git::get_new_command_with_git_support, Rule};

fn auxiliary_match_rule(command: &CrabCommand) -> bool {
if let Some(stdout) = &command.output {
command.script.contains("pull") && stdout.contains("set-upstream")
Expand Down
29 changes: 14 additions & 15 deletions src/rules/git_tag_force.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
use crate::{
cli::command::CrabCommand,
rules::{match_rule_with_git_support, utils::git::get_new_command_with_git_support},
Rule,
rules::{
utils::git::{get_new_command_with_git_support, match_rule_with_git_support},
Rule,
},
shell::Shell,
};
use shell::Shell;

fn auxiliary_match_rule(command: &CrabCommand) -> bool {
command.script.split_whitespace().any(|part| part == "tag")
&& command
.output
.as_ref()
.map_or(false, |o| o.contains("already exists"))
if let Some(output) = &command.output {
command.script_parts.contains(&"tag".to_string()) && output.contains("already exists")
} else {
false
}
}

pub fn match_rule(command: &mut CrabCommand, _system_shell: Option<&dyn Shell>) -> bool {
pub fn match_rule(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> bool {
match_rule_with_git_support(auxiliary_match_rule, command)
}

fn auxiliary_get_new_command(
command: &CrabCommand,
_system_shell: Option<&dyn Shell>,
system_shell: Option<&dyn Shell>,
) -> Vec<String> {
let new_script = command.script.replacen("tag", "tag --force", 1);
vec![new_script]
}

pub fn get_new_command(
command: &mut CrabCommand,
_system_shell: Option<&dyn Shell>,
) -> Vec<String> {
get_new_command_with_git_support(auxiliary_get_new_command, command, _system_shell)
pub fn get_new_command(command: &mut CrabCommand, system_shell: Option<&dyn Shell>) -> Vec<String> {
get_new_command_with_git_support(auxiliary_get_new_command, command, system_shell)
}

pub fn get_rule() -> Rule {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ mod git_push_without_commits;
mod git_rebase_merge_dir;
mod git_rebase_no_changes;
mod git_remote_delete;
mod git_tag_force;
mod git_remote_seturl_add;
mod git_rm_local_modifications;
mod git_rm_recursive;
mod git_rm_staged;
mod git_stash;
mod git_stash_pop;
mod git_tag_force;
mod git_two_dashes;
mod go_run;
mod gradle_wrapper;
Expand Down

0 comments on commit 7bd66cf

Please sign in to comment.