Skip to content

Commit 866380b

Browse files
committed
main: write a template .csmrc as well
1 parent b3def14 commit 866380b

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/main.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

templates/csmrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
env_create:
2+
# ssl_verify: true
3+
4+
# Optional, defaults to the system ca-certificates
5+
# ssl_bundle: /path/to/file.pem
6+
7+
# When true, instructs micromamba to not check certificate revocation when using
8+
# curl-based network operations.
9+
# ssl_no_revoke: false

templates/mambarc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# proxy_servers:
22
# http: http://user:pass@corp.com:8080
3-
# https: https://user:pass@corp.com:8080
3+
# https: https://user:pass@corp.com:8080

0 commit comments

Comments
 (0)