Skip to content

Commit d6ddd9b

Browse files
committed
fix(tests): dont take &CliArgs
1 parent b9c0211 commit d6ddd9b

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/keys/key_config.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ use anyhow::{anyhow, Result};
22
use crossterm::event::{KeyCode, KeyModifiers};
33
use std::{fs::canonicalize, path::PathBuf, rc::Rc};
44

5-
use crate::{
6-
args::{get_app_config_path, CliArgs},
7-
strings::symbol,
8-
};
5+
use crate::{args::get_app_config_path, strings::symbol};
96

107
use super::{
118
key_list::{GituiKeyEvent, KeysList},
@@ -37,8 +34,11 @@ impl KeyConfig {
3734
.map_or_else(|_| Ok(symbols_file), Ok)
3835
}
3936

40-
pub fn init(cli_args: &CliArgs) -> Result<Self> {
41-
let keys = if let Some(path) = &cli_args.key_bindings_path {
37+
pub fn init(
38+
key_bindings_path: Option<&PathBuf>,
39+
key_symbols_path: Option<&PathBuf>,
40+
) -> Result<Self> {
41+
let keys = if let Some(path) = key_bindings_path {
4242
if !path.exists() {
4343
return Err(anyhow!(
4444
"The custom key bindings file dosen't exists"
@@ -49,7 +49,7 @@ impl KeyConfig {
4949
KeysList::init(Self::get_config_file()?)
5050
};
5151

52-
let symbols = if let Some(path) = &cli_args.key_symbols_path {
52+
let symbols = if let Some(path) = key_symbols_path {
5353
if !path.exists() {
5454
return Err(anyhow!(
5555
"The custom key symbols file dosen't exists"
@@ -208,7 +208,7 @@ mod tests {
208208

209209
// testing
210210
let result = std::panic::catch_unwind(|| {
211-
let loaded_config = KeyConfig::init().unwrap();
211+
let loaded_config = KeyConfig::init(None, None).unwrap();
212212
assert_eq!(
213213
loaded_config.keys.move_down,
214214
KeysList::default().move_down
@@ -223,7 +223,7 @@ mod tests {
223223
&original_key_symbols_path,
224224
)
225225
.unwrap();
226-
let loaded_config = KeyConfig::init().unwrap();
226+
let loaded_config = KeyConfig::init(None, None).unwrap();
227227
assert_eq!(
228228
loaded_config.keys.move_down,
229229
KeysList::default().move_down
@@ -235,7 +235,7 @@ mod tests {
235235
&original_key_list_path,
236236
)
237237
.unwrap();
238-
let loaded_config = KeyConfig::init().unwrap();
238+
let loaded_config = KeyConfig::init(None, None).unwrap();
239239
assert_eq!(
240240
loaded_config.keys.move_down,
241241
GituiKeyEvent::new(
@@ -246,7 +246,7 @@ mod tests {
246246
assert_eq!(loaded_config.symbols.esc, "Esc");
247247

248248
fs::remove_file(&original_key_symbols_path).unwrap();
249-
let loaded_config = KeyConfig::init().unwrap();
249+
let loaded_config = KeyConfig::init(None, None).unwrap();
250250
assert_eq!(
251251
loaded_config.keys.move_down,
252252
GituiKeyEvent::new(

src/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,12 @@ fn main() -> Result<()> {
170170
asyncgit::register_tracing_logging();
171171
ensure_valid_path(&cliargs.repo_path)?;
172172

173-
let key_config = KeyConfig::init(&cliargs)
174-
.map_err(|e| log_eprintln!("KeyConfig loading error: {e}"))
175-
.unwrap_or_default();
173+
let key_config = KeyConfig::init(
174+
cliargs.key_bindings_path.as_ref(),
175+
cliargs.key_symbols_path.as_ref(),
176+
)
177+
.map_err(|e| log_eprintln!("KeyConfig loading error: {e}"))
178+
.unwrap_or_default();
176179
let theme = Theme::init(&cliargs.theme);
177180

178181
setup_terminal()?;

0 commit comments

Comments
 (0)