1- use directories:: { BaseDirs , ProjectDirs } ;
2- use std:: path:: PathBuf ;
1+ use etcetera:: app_strategy:: Xdg ;
2+ use etcetera:: { choose_app_strategy, AppStrategy , AppStrategyArgs } ;
3+ use std:: path:: { Path , PathBuf } ;
34use std:: sync:: OnceLock ;
45
56pub struct Dirs ;
@@ -8,26 +9,43 @@ impl Dirs {
89 /// Project directory specifically for Vim Clap.
910 ///
1011 /// All the files created by vim-clap are stored there.
11- pub fn project ( ) -> & ' static ProjectDirs {
12- static CELL : OnceLock < ProjectDirs > = OnceLock :: new ( ) ;
12+ pub fn project ( ) -> & ' static Xdg {
13+ static CELL : OnceLock < Xdg > = OnceLock :: new ( ) ;
1314
1415 CELL . get_or_init ( || {
15- ProjectDirs :: from ( "org" , "vim" , "Vim Clap" )
16- . expect ( "Couldn't create project directory for vim-clap" )
16+ choose_app_strategy ( AppStrategyArgs {
17+ top_level_domain : "org" . to_string ( ) ,
18+ author : "vim" . to_owned ( ) ,
19+ app_name : "Vim Clap" . to_owned ( ) ,
20+ } )
21+ . expect ( "Couldn't create project directory for vim-clap" )
1722 } )
1823 }
1924
20- /// Provides access to the standard directories that the operating system uses.
21- pub fn base ( ) -> & ' static BaseDirs {
22- static CELL : OnceLock < BaseDirs > = OnceLock :: new ( ) ;
25+ /// Get the home directory
26+ pub fn home_dir ( ) -> & ' static Path {
27+ Self :: project ( ) . home_dir ( )
28+ }
29+
30+ /// Get the config directory
31+ pub fn config_dir ( ) -> PathBuf {
32+ Self :: project ( ) . config_dir ( )
33+ }
34+
35+ /// Get the cache directory
36+ pub fn cache_dir ( ) -> PathBuf {
37+ Self :: project ( ) . cache_dir ( )
38+ }
2339
24- CELL . get_or_init ( || BaseDirs :: new ( ) . expect ( "Failed to construct BaseDirs" ) )
40+ /// Get the data directory
41+ pub fn data_dir ( ) -> PathBuf {
42+ Self :: project ( ) . data_dir ( )
2543 }
2644
2745 /// Cache directory for Vim Clap project.
2846 pub fn clap_cache_dir ( ) -> std:: io:: Result < PathBuf > {
2947 let cache_dir = Self :: project ( ) . cache_dir ( ) ;
30- std:: fs:: create_dir_all ( cache_dir) ?;
31- Ok ( cache_dir. to_path_buf ( ) )
48+ std:: fs:: create_dir_all ( & cache_dir) ?;
49+ Ok ( cache_dir)
3250 }
3351}
0 commit comments