@@ -107,13 +107,13 @@ fn main() -> ExitCode {
107107 return ExitCode :: FAILURE ;
108108 } ;
109109
110- if let Err ( e ) = create_mambarc ( & config , & home ) {
111- let attempted_path = home . join ( ".mambarc " ) ;
112- warn ! (
113- "Could not create {}, but continuing: {}" ,
114- attempted_path . display ( ) ,
115- e
116- ) ;
110+ let mambarc = include_str ! ( "../templates/mambarc" ) ;
111+ let csmrc = include_str ! ( "../templates/csmrc " ) ;
112+ for ( dotfile , contents ) in [ ( ".mambarc" , mambarc ) , ( ".csmrc" , csmrc ) ] {
113+ let path = home . join ( dotfile ) ;
114+ if let Err ( e ) = create_config_file ( & config , & path , contents ) {
115+ warn ! ( "Could not create {}, but continuing: {}" , path . display ( ) , e ) ;
116+ }
117117 }
118118
119119 #[ cfg( windows) ]
@@ -155,24 +155,20 @@ fn main() -> ExitCode {
155155 }
156156}
157157
158- /// Create a ~/.mambarc (%UserProfile%\.mambarc on Windows) if it does not
159- /// exist.
160- fn create_mambarc ( config : & Config , home : & Path ) -> std:: io:: Result < ( ) > {
161- let mambarc = include_str ! ( "../templates/mambarc" ) ;
162- let mambarc_path = home. join ( ".mambarc" ) ;
163-
164- if config. noop_mode && !mambarc_path. exists ( ) {
165- info ! ( "Would create {}" , mambarc_path. display( ) ) ;
158+ /// Create a configuration file (e.g. .mambarc or .csmrc) if it does not exist.
159+ fn create_config_file ( config : & Config , path : & Path , contents : & str ) -> std:: io:: Result < ( ) > {
160+ if config. noop_mode && !path. exists ( ) {
161+ info ! ( "Would create {}" , path. display( ) ) ;
166162 return Ok ( ( ) ) ;
167163 }
168164
169- match File :: create_new ( & mambarc_path) {
170- Ok ( mut file) => file. write_all ( mambarc. trim_start ( ) . as_bytes ( ) ) ?,
165+ match File :: create_new ( & path) {
166+ Ok ( mut file) => {
167+ file. write_all ( contents. trim_start ( ) . as_bytes ( ) ) ?;
168+ debug ! ( "Created {}" , path. display( ) ) ;
169+ }
171170 Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: AlreadyExists => {
172- debug ! (
173- "File {} already exists, not creating" ,
174- mambarc_path. display( )
175- )
171+ debug ! ( "File {} already exists, not creating" , path. display( ) )
176172 }
177173 Err ( e) => return Err ( e) ,
178174 }
0 commit comments