@@ -2,6 +2,10 @@ mod env;
22mod robot;
33
44use clap:: { Parser , Subcommand } ;
5+ use log:: debug;
6+ use std:: fs:: File ;
7+ use std:: io:: Write ;
8+ use std:: path:: PathBuf ;
59
610#[ derive( Parser , Debug ) ]
711#[ command( version) ]
@@ -23,9 +27,39 @@ enum Command {
2327}
2428
2529fn main ( ) {
30+ env_logger:: init ( ) ;
31+ let _ = create_mambarc ( ) ;
2632 let cli = Cli :: parse ( ) ;
2733 match cli. command {
2834 Command :: Env ( sub) => env:: run ( sub) ,
2935 Command :: Robot ( sub) => robot:: run ( sub) ,
3036 }
3137}
38+
39+ fn create_mambarc ( ) -> std:: io:: Result < ( ) > {
40+ let mambarc = r#"
41+ # Show the active environment in the shell prompt
42+ changeps1: True
43+
44+ # proxy_servers:
45+ # http: http://user:pass@corp.com:8080_
46+ # https: https://user:pass@corp.com:8080_
47+
48+ # Use this only if you are behind a proxy that does SSL inspection
49+ # ssl_verify: false
50+ # ssl_verify: mycorpcert.crt
51+ # ssl_no_revoke: true
52+ "# ;
53+ let home = std:: env:: var ( "HOME" )
54+ . or_else ( |_| std:: env:: var ( "USERPROFILE" ) )
55+ . expect ( "Cannot determine home directory" ) ;
56+ let mambarc_path = PathBuf :: from ( home) . join ( ".mambarc" ) ;
57+ match File :: create_new ( & mambarc_path) {
58+ Ok ( mut file) => file. write_all ( mambarc. trim_start ( ) . as_bytes ( ) ) ?,
59+ Err ( e) if e. kind ( ) == std:: io:: ErrorKind :: AlreadyExists => {
60+ debug ! ( "File {mambarc_path:?} already exists, not creating" )
61+ }
62+ Err ( e) => return Err ( e) ,
63+ }
64+ Ok ( ( ) )
65+ }
0 commit comments