fix: allow pre-command without command in custom mode
This commit is contained in:
parent
0544eb0582
commit
bc8f0de5c3
2 changed files with 13 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "lines"
|
||||
version = "0.1.17"
|
||||
version = "0.1.18"
|
||||
edition = "2024"
|
||||
authors = ["janvete"]
|
||||
description = "TUI for running frequently used commands"
|
||||
|
|
|
|||
|
|
@ -2,7 +2,9 @@ use crate::app::CustomState;
|
|||
|
||||
pub fn build_commands(state: &CustomState) -> Vec<String> {
|
||||
let command = state.command.trim();
|
||||
if command.is_empty() {
|
||||
let pre_command = state.pre_command.trim();
|
||||
|
||||
if command.is_empty() && pre_command.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
|
|
@ -11,7 +13,6 @@ pub fn build_commands(state: &CustomState) -> Vec<String> {
|
|||
return Vec::new();
|
||||
}
|
||||
|
||||
let pre_command = state.pre_command.trim();
|
||||
let prefix = if pre_command.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
|
|
@ -22,7 +23,9 @@ pub fn build_commands(state: &CustomState) -> Vec<String> {
|
|||
.iter()
|
||||
.map(|line| {
|
||||
let line = line.trim();
|
||||
let built = if command.contains("{}") {
|
||||
let built = if command.is_empty() {
|
||||
line.to_string()
|
||||
} else if command.contains("{}") {
|
||||
command.replace("{}", line)
|
||||
} else {
|
||||
format!("{} \"{}\"", line, command.replace('"', "\\\""))
|
||||
|
|
@ -116,4 +119,10 @@ mod tests {
|
|||
vec!["lview ssh root@ip1 lsblk", "lview ssh root@ip2 lsblk"]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_build_commands_pre_command_only() {
|
||||
let state = make_state(vec!["ssh root@ip1", "ssh root@ip2"], vec![false, true], "", "lview");
|
||||
assert_eq!(build_commands(&state), vec!["lview ssh root@ip2"]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue