Skip to content

Commit 0245433

Browse files
committed
Write a .mambarc on first use
Signed-off-by: Rick Elrod <rick.elrod@checkmk.com>
1 parent 4a4c09d commit 0245433

3 files changed

Lines changed: 179 additions & 0 deletions

File tree

Cargo.lock

Lines changed: 143 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ edition = "2024"
55

66
[dependencies]
77
clap = { version = "4.5.50", features = ["derive", "wrap_help"] }
8+
env_logger = "0.11.8"
9+
log = "0.4.28"

src/main.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ mod env;
22
mod robot;
33

44
use 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

2529
fn 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

Comments
 (0)