@@ -4,7 +4,6 @@ use std::{
44 path:: { Path , PathBuf } ,
55} ;
66
7- use etcetera:: BaseStrategy ;
87use serde:: { Deserialize , Serialize } ;
98
109use crate :: {
@@ -103,13 +102,6 @@ impl Config {
103102 Ok ( config)
104103 }
105104
106- /// Returns the default global config file location
107- pub fn global_config_path ( ) -> Option < PathBuf > {
108- etcetera:: choose_base_strategy ( )
109- . ok ( )
110- . map ( |strat| strat. config_dir ( ) . join ( "wasm-pkg" ) . join ( "config.toml" ) )
111- }
112-
113105 /// Reads config from the default global config file location
114106 pub async fn read_global_config ( ) -> Result < Option < Self > , Error > {
115107 let path = match Config :: global_config_path ( ) {
@@ -124,6 +116,14 @@ impl Config {
124116 Ok ( Some ( Self :: from_toml ( & contents) ?) )
125117 }
126118
119+ /// Returns the default global config file location
120+ pub fn global_config_path ( ) -> Option < PathBuf > {
121+ use etcetera:: BaseStrategy ;
122+ etcetera:: choose_base_strategy ( )
123+ . ok ( )
124+ . map ( |strat| strat. config_dir ( ) . join ( "wasm-pkg" ) . join ( "config.toml" ) )
125+ }
126+
127127 /// Reads config from a TOML file at the given path.
128128 pub async fn from_file ( path : impl AsRef < Path > ) -> Result < Self , Error > {
129129 let contents = tokio:: fs:: read_to_string ( path)
@@ -134,14 +134,13 @@ impl Config {
134134
135135 /// Parses config from the given TOML contents.
136136 pub fn from_toml ( contents : & str ) -> Result < Self , Error > {
137- let toml_cfg: toml:: TomlConfig =
138- :: toml:: from_str ( contents) . map_err ( Error :: invalid_config) ?;
137+ let toml_cfg: toml:: TomlConfig = :: toml:: from_str ( contents) . map_err ( invalid_config) ?;
139138 Ok ( toml_cfg. into ( ) )
140139 }
141140
142141 /// Writes the config to a TOML file at the given path.
143142 pub async fn to_file ( & self , path : impl AsRef < Path > ) -> Result < ( ) , Error > {
144- let toml_str = :: toml:: to_string ( & self ) . map_err ( Error :: invalid_config) ?;
143+ let toml_str = :: toml:: to_string ( & self ) . map_err ( invalid_config) ?;
145144 tokio:: fs:: write ( path, toml_str)
146145 . await
147146 . map_err ( Error :: ConfigFileIoError )
@@ -330,7 +329,7 @@ impl RegistryConfig {
330329 let Some ( table) = self . backend_configs . get ( backend_type) else {
331330 return Ok ( None ) ;
332331 } ;
333- let config = table. clone ( ) . try_into ( ) . map_err ( Error :: invalid_config) ?;
332+ let config = table. clone ( ) . try_into ( ) . map_err ( invalid_config) ?;
334333 Ok ( Some ( config) )
335334 }
336335
@@ -340,7 +339,7 @@ impl RegistryConfig {
340339 backend_type : impl Into < String > ,
341340 backend_config : T ,
342341 ) -> Result < ( ) , Error > {
343- let table = :: toml:: Table :: try_from ( backend_config) . map_err ( Error :: invalid_config) ?;
342+ let table = :: toml:: Table :: try_from ( backend_config) . map_err ( invalid_config) ?;
344343 self . backend_configs . insert ( backend_type. into ( ) , table) ;
345344 Ok ( ( ) )
346345 }
@@ -368,3 +367,7 @@ impl std::fmt::Debug for DebugBackendConfigs<'_> {
368367 . finish ( )
369368 }
370369}
370+
371+ fn invalid_config ( err : impl Into < anyhow:: Error > ) -> Error {
372+ Error :: InvalidConfig ( err. into ( ) )
373+ }
0 commit comments