Skip to content

Commit ab5f918

Browse files
committed
main: write a template .csmrc as well
1 parent 3ae3248 commit ab5f918

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

src/main.rs

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

templates/csmrc

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