|
1 | | -use anyhow::Result; |
| 1 | +use anyhow::{anyhow, Result}; |
2 | 2 | use crossterm::event::{KeyCode, KeyModifiers}; |
3 | 3 | use std::{fs::canonicalize, path::PathBuf, rc::Rc}; |
4 | 4 |
|
5 | | -use crate::{args::get_app_config_path, strings::symbol}; |
| 5 | +use crate::{ |
| 6 | + args::{get_app_config_path, CliArgs}, |
| 7 | + strings::symbol, |
| 8 | +}; |
6 | 9 |
|
7 | 10 | use super::{ |
8 | 11 | key_list::{GituiKeyEvent, KeysList}, |
@@ -34,9 +37,29 @@ impl KeyConfig { |
34 | 37 | .map_or_else(|_| Ok(symbols_file), Ok) |
35 | 38 | } |
36 | 39 |
|
37 | | - pub fn init() -> Result<Self> { |
38 | | - let keys = KeysList::init(Self::get_config_file()?); |
39 | | - let symbols = KeySymbols::init(Self::get_symbols_file()?); |
| 40 | + pub fn init(cli_args: &CliArgs) -> Result<Self> { |
| 41 | + let keys = if let Some(path) = &cli_args.key_bindings_path { |
| 42 | + if !path.exists() { |
| 43 | + return Err(anyhow!( |
| 44 | + "The custom key bindings file dosen't exists" |
| 45 | + )); |
| 46 | + } |
| 47 | + KeysList::init(path.to_path_buf()) |
| 48 | + } else { |
| 49 | + KeysList::init(Self::get_config_file()?) |
| 50 | + }; |
| 51 | + |
| 52 | + let symbols = if let Some(path) = &cli_args.key_symbols_path { |
| 53 | + if !path.exists() { |
| 54 | + return Err(anyhow!( |
| 55 | + "The custom key symbols file dosen't exists" |
| 56 | + )); |
| 57 | + } |
| 58 | + KeySymbols::init(path.to_path_buf()) |
| 59 | + } else { |
| 60 | + KeySymbols::init(Self::get_symbols_file()?) |
| 61 | + }; |
| 62 | + |
40 | 63 | Ok(Self { keys, symbols }) |
41 | 64 | } |
42 | 65 |
|
|
0 commit comments