File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change 11use anyhow:: { Context , Result } ;
22use serde:: Deserialize ;
3- use std:: { env, fs, path:: PathBuf } ;
3+ use std:: { env, fs, path:: { Path , PathBuf } } ;
44
55/// Represents global application settings loaded from cmdy.toml.
66#[ derive( Debug , Deserialize ) ]
@@ -22,15 +22,15 @@ impl Default for AppConfig {
2222 }
2323}
2424
25- fn expand_tilde ( path : & PathBuf ) -> PathBuf {
25+ fn expand_tilde ( path : & Path ) -> PathBuf {
2626 if let Some ( path_str) = path. to_str ( ) {
27- if path_str. starts_with ( "~/" ) {
27+ if let Some ( stripped ) = path_str. strip_prefix ( "~/" ) {
2828 if let Ok ( home) = env:: var ( "HOME" ) {
29- return PathBuf :: from ( home) . join ( & path_str [ 2 .. ] ) ;
29+ return PathBuf :: from ( home) . join ( stripped ) ;
3030 }
3131 }
3232 }
33- path. clone ( )
33+ path. to_path_buf ( )
3434}
3535
3636/// Loads the application configuration from a TOML file.
@@ -54,7 +54,7 @@ pub fn load_app_config() -> Result<AppConfig> {
5454 . with_context ( || format ! ( "Failed to read config file: {}" , config_path. display( ) ) ) ?;
5555 match toml:: from_str :: < AppConfig > ( & content) {
5656 Ok ( mut cfg) => {
57- cfg. directories = cfg. directories . iter ( ) . map ( expand_tilde) . collect ( ) ;
57+ cfg. directories = cfg. directories . iter ( ) . map ( |p| expand_tilde ( p ) ) . collect ( ) ;
5858 return Ok ( cfg) ;
5959 }
6060 Err ( e) => eprintln ! (
You can’t perform that action at this time.
0 commit comments