-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
schema.rs
64 lines (51 loc) · 1.86 KB
/
schema.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
use shellexpand;
use std::collections::BTreeMap;
use std::path::PathBuf;
use crate::err;
use crate::model::asset_name::AssetName;
/// Stores global information about the tool installation process and detailed
/// info about installing each particular tool.
///
/// This data type is parsed from the TOML configuration file.
#[derive(Debug, PartialEq, Eq)]
pub struct Config {
/// Directory to store all locally downloaded tools
pub store_directory: String,
/// Info about each individual tool
pub tools: BTreeMap<String, ConfigAsset>,
}
/// Additional details, telling how to download a tool
#[derive(Debug, PartialEq, Eq)]
pub struct ConfigAsset {
/// GitHub repository author
pub owner: Option<String>,
/// GitHub repository name
pub repo: Option<String>,
/// Executable name inside the .tar.gz or .zip archive
/// Defaults to `repo` if not specified
pub exe_name: Option<String>,
/// Name of the specific asset to download
pub asset_name: AssetName,
/// Release tag to download
/// Defaults to the latest release
pub tag: Option<String>,
}
impl Config {
/// Shellexpands store directory, check whether it exists and exits with
/// error if 'store_directory' doesn't exist
pub fn ensure_store_directory(&self) -> PathBuf {
let expanded_store_directory = shellexpand::full(&self.store_directory);
let store_directory = match expanded_store_directory {
Err(e) => err::abort_with(&e.to_string()),
Ok(cow_path) => PathBuf::from(cow_path.into_owned()),
};
let has_store_directory = store_directory.as_path().is_dir();
if !has_store_directory {
err::abort_with(&format!(
"Specified directory for storing tools doesn't exist: {}",
store_directory.display()
));
}
store_directory
}
}