juliaup/
command_config_modifypath.rs1#[cfg(feature = "selfupdate")]
2pub fn run_command_config_modifypath(
3 value: Option<bool>,
4 quiet: bool,
5 paths: &crate::global_paths::GlobalPaths,
6) -> anyhow::Result<()> {
7 use crate::config_file::{load_config_db, load_mut_config_db, save_config_db};
8 use crate::operations::{
9 add_binfolder_to_path_in_shell_scripts, remove_binfolder_from_path_in_shell_scripts,
10 };
11 use anyhow::Context;
12
13 match value {
14 Some(value) => {
15 let mut config_file = load_mut_config_db(paths)
16 .with_context(|| "`config` command failed to load configuration data.")?;
17
18 let mut value_changed = false;
19
20 if value != config_file.self_data.modify_path {
21 config_file.self_data.modify_path = value;
22
23 value_changed = true;
24 }
25
26 if value {
27 add_binfolder_to_path_in_shell_scripts(&paths.juliaupselfbin)?;
28 } else {
29 remove_binfolder_from_path_in_shell_scripts()?;
30 }
31
32 save_config_db(&mut config_file)
33 .with_context(|| "Failed to save configuration file from `config` command.")?;
34
35 if !quiet {
36 if value_changed {
37 eprintln!("Property 'modifypath' set to '{}'", value);
38 } else {
39 eprintln!("Property 'modifypath' is already set to '{}'", value);
40 }
41 }
42 }
43 None => {
44 let config_file = load_config_db(paths, None)
45 .with_context(|| "`config` command failed to load configuration data.")?;
46
47 if !quiet {
48 eprintln!(
49 "Property 'modifypath' set to '{}'",
50 config_file.self_data.modify_path
51 );
52 }
53 }
54 };
55
56 Ok(())
57}