@@ -6,7 +6,7 @@ use crate::error::{KeyringError, Result};
66use crate :: tui:: keybindings:: KeyBindingManager ;
77use clap:: Parser ;
88use std:: fs;
9- use std:: path:: PathBuf ;
9+ use std:: path:: { Path , PathBuf } ;
1010use std:: process:: Command ;
1111
1212#[ derive( Parser , Debug ) ]
@@ -35,10 +35,9 @@ pub async fn manage_keybindings(args: KeybindingsArgs) -> Result<()> {
3535 // Ensure config directory exists
3636 if let Some ( parent) = config_path. parent ( ) {
3737 if !parent. exists ( ) {
38- fs:: create_dir_all ( parent) . map_err ( |e| KeyringError :: IoError ( format ! (
39- "Failed to create config directory: {}" ,
40- e
41- ) ) ) ?;
38+ fs:: create_dir_all ( parent) . map_err ( |e| {
39+ KeyringError :: IoError ( format ! ( "Failed to create config directory: {}" , e) )
40+ } ) ?;
4241 }
4342 }
4443
@@ -65,12 +64,15 @@ fn get_config_path() -> PathBuf {
6564 config_dir. join ( "open-keyring" ) . join ( "keybindings.yaml" )
6665 } else {
6766 let home = std:: env:: var ( "HOME" ) . unwrap_or_else ( |_| "." . to_string ( ) ) ;
68- PathBuf :: from ( home) . join ( ".config" ) . join ( "open-keyring" ) . join ( "keybindings.yaml" )
67+ PathBuf :: from ( home)
68+ . join ( ".config" )
69+ . join ( "open-keyring" )
70+ . join ( "keybindings.yaml" )
6971 }
7072}
7173
7274/// List all keyboard shortcuts
73- fn list_keybindings ( config_path : & PathBuf ) -> Result < ( ) > {
75+ fn list_keybindings ( config_path : & Path ) -> Result < ( ) > {
7476 let manager = KeyBindingManager :: new ( ) ;
7577 let bindings = manager. all_bindings ( ) ;
7678
@@ -95,7 +97,7 @@ fn list_keybindings(config_path: &PathBuf) -> Result<()> {
9597}
9698
9799/// Validate keybindings configuration
98- fn validate_keybindings ( config_path : & PathBuf ) -> Result < ( ) > {
100+ fn validate_keybindings ( config_path : & Path ) -> Result < ( ) > {
99101 println ! ( "🔍 Validating keybindings configuration..." ) ;
100102 println ! ( " File: {}" , config_path. display( ) ) ;
101103 println ! ( ) ;
@@ -106,10 +108,8 @@ fn validate_keybindings(config_path: &PathBuf) -> Result<()> {
106108 }
107109
108110 // Try to parse the file
109- let content = fs:: read_to_string ( config_path) . map_err ( |e| KeyringError :: IoError ( format ! (
110- "Failed to read config file: {}" ,
111- e
112- ) ) ) ?;
111+ let content = fs:: read_to_string ( config_path)
112+ . map_err ( |e| KeyringError :: IoError ( format ! ( "Failed to read config file: {}" , e) ) ) ?;
113113
114114 match serde_yaml:: from_str :: < serde_yaml:: Value > ( & content) {
115115 Ok ( value) => {
@@ -124,11 +124,16 @@ fn validate_keybindings(config_path: &PathBuf) -> Result<()> {
124124 if let Some ( shortcut_str) = shortcut_val. as_str ( ) {
125125 if let Some ( existing_action) = seen. get ( shortcut_str) {
126126 let action_str = action_key. as_str ( ) . unwrap_or ( "?" ) ;
127- println ! ( "⚠️ Conflict: '{}' is used by both '{}' and '{}'" ,
128- shortcut_str, existing_action, action_str) ;
127+ println ! (
128+ "⚠️ Conflict: '{}' is used by both '{}' and '{}'" ,
129+ shortcut_str, existing_action, action_str
130+ ) ;
129131 has_conflicts = true ;
130132 } else {
131- seen. insert ( shortcut_str. to_string ( ) , action_key. as_str ( ) . unwrap_or ( "?" ) . to_string ( ) ) ;
133+ seen. insert (
134+ shortcut_str. to_string ( ) ,
135+ action_key. as_str ( ) . unwrap_or ( "?" ) . to_string ( ) ,
136+ ) ;
132137 }
133138 }
134139 }
@@ -140,16 +145,14 @@ fn validate_keybindings(config_path: &PathBuf) -> Result<()> {
140145
141146 Ok ( ( ) )
142147 }
143- Err ( e) => {
144- Err ( KeyringError :: InvalidInput {
145- context : format ! ( "Invalid YAML: {}" , e) ,
146- } )
147- }
148+ Err ( e) => Err ( KeyringError :: InvalidInput {
149+ context : format ! ( "Invalid YAML: {}" , e) ,
150+ } ) ,
148151 }
149152}
150153
151154/// Reset keybindings to defaults
152- fn reset_keybindings ( config_path : & PathBuf ) -> Result < ( ) > {
155+ fn reset_keybindings ( config_path : & Path ) -> Result < ( ) > {
153156 println ! ( "🔄 Resetting keybindings to defaults..." ) ;
154157
155158 // Write default configuration
@@ -163,7 +166,7 @@ fn reset_keybindings(config_path: &PathBuf) -> Result<()> {
163166}
164167
165168/// Edit keybindings configuration
166- fn edit_keybindings ( config_path : & PathBuf ) -> Result < ( ) > {
169+ fn edit_keybindings ( config_path : & Path ) -> Result < ( ) > {
167170 // Ensure default config exists
168171 if !config_path. exists ( ) {
169172 fs:: write ( config_path, crate :: tui:: keybindings:: DEFAULT_KEYBINDINGS )
@@ -266,7 +269,7 @@ mod tests {
266269 fn test_keybindings_args_list ( ) {
267270 use clap:: Parser ;
268271
269- let args = KeybindingsArgs :: parse_from ( & [ "ok" , "keybindings" , " --list"] ) ;
272+ let args = KeybindingsArgs :: parse_from ( & [ "ok" , "--list" ] ) ;
270273 assert ! ( args. list) ;
271274 assert ! ( !args. validate) ;
272275 assert ! ( !args. reset) ;
@@ -277,7 +280,7 @@ mod tests {
277280 fn test_keybindings_args_validate ( ) {
278281 use clap:: Parser ;
279282
280- let args = KeybindingsArgs :: parse_from ( & [ "ok" , "keybindings" , " --validate"] ) ;
283+ let args = KeybindingsArgs :: parse_from ( & [ "ok" , "--validate" ] ) ;
281284 assert ! ( args. validate) ;
282285 assert ! ( !args. list) ;
283286 }
@@ -286,7 +289,7 @@ mod tests {
286289 fn test_keybindings_args_reset ( ) {
287290 use clap:: Parser ;
288291
289- let args = KeybindingsArgs :: parse_from ( & [ "ok" , "keybindings" , " --reset"] ) ;
292+ let args = KeybindingsArgs :: parse_from ( & [ "ok" , "--reset" ] ) ;
290293 assert ! ( args. reset) ;
291294 assert ! ( !args. list) ;
292295 }
@@ -295,7 +298,7 @@ mod tests {
295298 fn test_keybindings_args_edit ( ) {
296299 use clap:: Parser ;
297300
298- let args = KeybindingsArgs :: parse_from ( & [ "ok" , "keybindings" , " --edit"] ) ;
301+ let args = KeybindingsArgs :: parse_from ( & [ "ok" , "--edit" ] ) ;
299302 assert ! ( args. edit) ;
300303 assert ! ( !args. list) ;
301304 }
0 commit comments