Skip to content

Commit 70dc4af

Browse files
committed
fix(tests): dont take &CliArgs
1 parent 5a14779 commit 70dc4af

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"
@@ -216,7 +216,7 @@ mod tests {
216216

217217
// testing
218218
let result = std::panic::catch_unwind(|| {
219-
let loaded_config = KeyConfig::init().unwrap();
219+
let loaded_config = KeyConfig::init(None, None).unwrap();
220220
assert_eq!(
221221
loaded_config.keys.move_down,
222222
KeysList::default().move_down
@@ -231,7 +231,7 @@ mod tests {
231231
&original_key_symbols_path,
232232
)
233233
.unwrap();
234-
let loaded_config = KeyConfig::init().unwrap();
234+
let loaded_config = KeyConfig::init(None, None).unwrap();
235235
assert_eq!(
236236
loaded_config.keys.move_down,
237237
KeysList::default().move_down
@@ -243,7 +243,7 @@ mod tests {
243243
&original_key_list_path,
244244
)
245245
.unwrap();
246-
let loaded_config = KeyConfig::init().unwrap();
246+
let loaded_config = KeyConfig::init(None, None).unwrap();
247247
assert_eq!(
248248
loaded_config.keys.move_down,
249249
GituiKeyEvent::new(
@@ -254,7 +254,7 @@ mod tests {
254254
assert_eq!(loaded_config.symbols.esc, "Esc");
255255

256256
fs::remove_file(&original_key_symbols_path).unwrap();
257-
let loaded_config = KeyConfig::init().unwrap();
257+
let loaded_config = KeyConfig::init(None, None).unwrap();
258258
assert_eq!(
259259
loaded_config.keys.move_down,
260260
GituiKeyEvent::new(

src/main.rs

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

169-
let key_config = KeyConfig::init(&cliargs)
170-
.map_err(|e| log_eprintln!("KeyConfig loading error: {e}"))
171-
.unwrap_or_default();
169+
let key_config = KeyConfig::init(
170+
cliargs.key_bindings_path.as_ref(),
171+
cliargs.key_symbols_path.as_ref(),
172+
)
173+
.map_err(|e| log_eprintln!("KeyConfig loading error: {e}"))
174+
.unwrap_or_default();
172175
let theme = Theme::init(&cliargs.theme);
173176

174177
setup_terminal()?;

0 commit comments

Comments
 (0)