-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathcommand_link.rs
68 lines (57 loc) · 2.32 KB
/
command_link.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::config_file::JuliaupConfigChannel;
use crate::config_file::{load_mut_config_db, save_config_db};
use crate::global_paths::GlobalPaths;
#[cfg(not(windows))]
use crate::operations::create_symlink;
use crate::operations::is_valid_channel;
use crate::utils::is_valid_julia_path;
use crate::versions_file::load_versions_db;
use anyhow::{bail, Context, Result};
use path_absolutize::Absolutize;
use std::path::Path;
pub fn run_command_link(
channel: &str,
file: &str,
args: &[String],
paths: &GlobalPaths,
) -> Result<()> {
let mut config_file = load_mut_config_db(paths)
.with_context(|| "`link` command failed to load configuration data.")?;
let versiondb_data =
load_versions_db(paths).with_context(|| "`link` command failed to load versions db.")?;
if config_file.data.installed_channels.contains_key(channel) {
bail!("Channel name `{}` is already used.", channel)
}
if is_valid_channel(&versiondb_data, &channel.to_string())? {
eprintln!("WARNING: The channel name `{}` is also a system channel. By linking your custom binary to this channel you are hiding this system channel.", channel);
}
let absolute_file_path = Path::new(file)
.absolutize()
.with_context(|| format!("Failed to convert path `{}` to absolute path.", file))?;
if !is_valid_julia_path(&absolute_file_path.to_path_buf()) {
eprintln!("WARNING: There is no julia binary at {}. If this was a mistake, run `juliaup remove {}` and try again.", absolute_file_path.to_string_lossy(), channel);
}
config_file.data.installed_channels.insert(
channel.to_string(),
JuliaupConfigChannel::LinkedChannel {
command: absolute_file_path.to_string_lossy().to_string(),
args: Some(args.to_vec()),
},
);
#[cfg(not(windows))]
let create_symlinks = config_file.data.settings.create_channel_symlinks;
save_config_db(&mut config_file)
.with_context(|| "`link` command failed to save configuration db.")?;
#[cfg(not(windows))]
if create_symlinks {
create_symlink(
&JuliaupConfigChannel::LinkedChannel {
command: file.to_string(),
args: Some(args.to_vec()),
},
&format!("julia-{}", channel),
paths,
)?;
}
Ok(())
}