juliaup/
command_config_symlinks.rs1#[cfg(not(windows))]
2use anyhow::Result;
3
4#[cfg(not(windows))]
5pub fn run_command_config_symlinks(
6 value: Option<bool>,
7 quiet: bool,
8 paths: &crate::global_paths::GlobalPaths,
9) -> Result<()> {
10 use crate::config_file::{load_config_db, load_mut_config_db, save_config_db};
11 use crate::operations::{create_symlink, remove_symlink};
12 use crate::utils::{print_juliaup_style, JuliaupMessageType};
13 use anyhow::Context;
14
15 match value {
16 Some(value) => {
17 let mut config_file = load_mut_config_db(paths)
18 .with_context(|| "`config` command failed to load configuration data.")?;
19
20 let mut value_changed = false;
21
22 if value != config_file.data.settings.create_channel_symlinks {
23 config_file.data.settings.create_channel_symlinks = value;
24 value_changed = true;
25
26 for (channel_name, channel) in &config_file.data.installed_channels {
27 if value {
28 create_symlink(channel, &format!("julia-{}", channel_name), paths)?;
29 } else {
30 remove_symlink(&format!("julia-{}", channel_name))?;
31 }
32 }
33 }
34
35 save_config_db(&mut config_file)
36 .with_context(|| "Failed to save configuration file from `config` command.")?;
37
38 if !quiet {
39 if value_changed {
40 print_juliaup_style(
41 "Configure",
42 &format!("Property 'channelsymlinks' set to '{}'", value),
43 JuliaupMessageType::Success,
44 );
45 } else {
46 print_juliaup_style(
47 "Configure",
48 &format!("Property 'channelsymlinks' is already set to '{}'", value),
49 JuliaupMessageType::Success,
50 );
51 }
52 }
53 }
54 None => {
55 let config_file = load_config_db(paths, None)
56 .with_context(|| "`config` command failed to load configuration data.")?;
57
58 if !quiet {
59 print_juliaup_style(
60 "Configure",
61 &format!(
62 "Property 'channelsymlinks' set to '{}'",
63 config_file.data.settings.create_channel_symlinks
64 ),
65 JuliaupMessageType::Success,
66 );
67 }
68 }
69 };
70
71 Ok(())
72}