@@ -86,13 +86,13 @@ fn main() -> ExitCode {
8686 return ExitCode :: FAILURE ;
8787 } ;
8888
89- if let Err ( e ) = create_mambarc ( & config , & home ) {
90- let attempted_path = home . join ( ".mambarc " ) ;
91- warn ! (
92- "Could not create {}, but continuing: {}" ,
93- attempted_path . display ( ) ,
94- e
95- ) ;
89+ let mambarc = include_str ! ( "../templates/mambarc" ) ;
90+ let csmrc = include_str ! ( "../templates/csmrc " ) ;
91+ for ( dotfile , contents ) in [ ( ".mambarc" , mambarc ) , ( ".csmrc" , csmrc ) ] {
92+ let path = home . join ( dotfile ) ;
93+ if let Err ( e ) = create_config_file ( & config , & path , contents ) {
94+ warn ! ( "Could not create {}, but continuing: {}" , path . display ( ) , e ) ;
95+ }
9696 }
9797
9898 #[ cfg( windows) ]
@@ -134,24 +134,20 @@ fn main() -> ExitCode {
134134 }
135135}
136136
137- /// Create a ~/.mambarc (%UserProfile%\.mambarc on Windows) if it does not
138- /// exist.
139- fn create_mambarc ( config : & Config , home : & Path ) -> std:: io:: Result < ( ) > {
140- let mambarc = include_str ! ( "../templates/mambarc" ) ;
141- let mambarc_path = home. join ( ".mambarc" ) ;
142-
143- if config. noop_mode && !mambarc_path. exists ( ) {
144- info ! ( "Would create {}" , mambarc_path. display( ) ) ;
137+ /// Create a configuration file (e.g. .mambarc or .csmrc) if it does not exist.
138+ fn create_config_file ( config : & Config , path : & Path , contents : & str ) -> std:: io:: Result < ( ) > {
139+ if config. noop_mode && !path. exists ( ) {
140+ info ! ( "Would create {}" , path. display( ) ) ;
145141 return Ok ( ( ) ) ;
146142 }
147143
148- match File :: create_new ( & mambarc_path) {
149- Ok ( mut file) => file. write_all ( mambarc. trim_start ( ) . as_bytes ( ) ) ?,
144+ match File :: create_new ( path) {
145+ Ok ( mut file) => {
146+ file. write_all ( contents. trim_start ( ) . as_bytes ( ) ) ?;
147+ debug ! ( "Created {}" , path. display( ) ) ;
148+ }
150149 Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: AlreadyExists => {
151- debug ! (
152- "File {} already exists, not creating" ,
153- mambarc_path. display( )
154- )
150+ debug ! ( "File {} already exists, not creating" , path. display( ) )
155151 }
156152 Err ( e) => return Err ( e) ,
157153 }
0 commit comments