@@ -16,15 +16,22 @@ nest! {
1616
1717/// Get the path to the configuration file, following the XDG Base Directory Specification
1818/// at https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
19- fn get_configuration_file_path ( ) -> PathBuf {
19+ ///
20+ /// If config_name is None, returns ~/.config/codspeed/config.yaml (default)
21+ /// If config_name is Some, returns ~/.config/codspeed/{config_name}.yaml
22+ fn get_configuration_file_path ( config_name : Option < & str > ) -> PathBuf {
2023 let config_dir = env:: var ( "XDG_CONFIG_HOME" )
2124 . map ( PathBuf :: from)
2225 . unwrap_or_else ( |_| {
2326 let home = env:: var ( "HOME" ) . expect ( "HOME env variable not set" ) ;
2427 PathBuf :: from ( home) . join ( ".config" )
2528 } ) ;
2629 let config_dir = config_dir. join ( "codspeed" ) ;
27- config_dir. join ( "config.yaml" )
30+
31+ match config_name {
32+ Some ( name) => config_dir. join ( format ! ( "{name}.yaml" ) ) ,
33+ None => config_dir. join ( "config.yaml" ) ,
34+ }
2835}
2936
3037impl Default for CodSpeedConfig {
@@ -40,15 +47,19 @@ impl CodSpeedConfig {
4047 ///
4148 /// If oauth_token_override is provided, the token from the loaded configuration will be
4249 /// ignored, and the override will be used instead
43- pub fn load_with_override ( oauth_token_override : Option < & str > ) -> Result < Self > {
44- let config_path = get_configuration_file_path ( ) ;
50+ pub fn load_with_override (
51+ config_name : Option < & str > ,
52+ oauth_token_override : Option < & str > ,
53+ ) -> Result < Self > {
54+ let config_path = get_configuration_file_path ( config_name) ;
4555
4656 let mut config = match fs:: read ( & config_path) {
4757 Ok ( config_str) => {
48- let config = serde_yaml:: from_slice ( & config_str) . context ( format ! (
49- "Failed to parse CodSpeed config at {}" ,
50- config_path. display( )
51- ) ) ?;
58+ let config: CodSpeedConfig =
59+ serde_yaml:: from_slice ( & config_str) . context ( format ! (
60+ "Failed to parse CodSpeed config at {}" ,
61+ config_path. display( )
62+ ) ) ?;
5263 debug ! ( "Config loaded from {}" , config_path. display( ) ) ;
5364 config
5465 }
@@ -66,14 +77,9 @@ impl CodSpeedConfig {
6677 Ok ( config)
6778 }
6879
69- /// Load the configuration. If it does not exist, return a default configuration.
70- pub fn load ( ) -> Result < Self > {
71- Self :: load_with_override ( None )
72- }
73-
7480 /// Persist changes to the configuration
75- pub fn persist ( & self ) -> Result < ( ) > {
76- let config_path = get_configuration_file_path ( ) ;
81+ pub fn persist ( & self , config_name : Option < & str > ) -> Result < ( ) > {
82+ let config_path = get_configuration_file_path ( config_name ) ;
7783 fs:: create_dir_all ( config_path. parent ( ) . unwrap ( ) ) ?;
7884
7985 let config_str = serde_yaml:: to_string ( self ) ?;
0 commit comments