Skip to content

Commit

Permalink
Implement install from spec
Browse files Browse the repository at this point in the history
  • Loading branch information
KonishchevDmitry committed Nov 22, 2024
1 parent 1dce521 commit 01a9e56
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 55 deletions.
188 changes: 188 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ easy-logging = "1"
flate2 = "1.0"
globset = "0.4.15"
http = "1.1.0"
indoc = "2.0.5"
is-terminal = "0.4.13"
itertools = "0.13.0"
octocrab = "0.42.0"
libc = "0.2.164"
log = "0.4.22"
nondestructive = "0.0.26"
platforms = "3.5.0"
regex = "1.11.1"
reqwest = { version = "0.12.9", features = ["blocking"] }
Expand All @@ -42,6 +44,7 @@ serde_yaml = "0.9.34"
shellexpand = "3.1.0"
tabled = { version = "0.16.0", features = ["ansi"] }
tar = "0.4.43"
textwrap = "0.16.1"
tokio = "1"
url = "2.5.3"
validator = { version = "0.19.0", features = ["derive"] }
Expand Down
1 change: 1 addition & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ pub fn parse_args() -> GenericResult<CliArgs> {
let mode = match command {
"install" => Mode::Install {
force: matches.get_flag("force"),
recheck_spec: false,
},
"upgrade" => Mode::Upgrade,
_ => unreachable!(),
Expand Down
21 changes: 16 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct Config {
source: Option<ConfigSource>,

#[serde(rename = "path", default = "default_install_path", deserialize_with = "util::deserialize_path")]
pub install_path: PathBuf,
pub path: PathBuf,

#[serde(default)]
#[validate(nested)]
Expand Down Expand Up @@ -53,7 +53,11 @@ impl Config {
Ok(config)
}

pub fn edit<F: FnOnce(&mut Config, &mut Document) -> EmptyResult>(&mut self, edit: F) -> EmptyResult {
pub fn edit<E, P>(&mut self, edit: E, process: P) -> EmptyResult
where
E: FnOnce(&mut Config, &mut Document) -> EmptyResult,
P: FnOnce(&Config) -> EmptyResult
{
let error_prefix = "Failed to edit the configuration file: its current format is not supported by the underlaying library.";

let mut expected_config = self.clone();
Expand All @@ -72,6 +76,12 @@ impl Config {
return Err!("{error_prefix} Got the following unexpected config:\n{result}");
}

source.data = result.into_bytes();
config.source.replace(source);
process(&config)?;

let source = config.source.as_mut().unwrap();

if !source.exists {
if let Some(path) = source.path.parent() {
fs::create_dir_all(path).map_err(|e| format!(
Expand All @@ -80,15 +90,16 @@ impl Config {
source.exists = true;
}

source.data = result.into_bytes();
Config::write(&source.path, &source.data)?;

config.source.replace(source);
*self = config;

Ok(())
}

pub fn get_tool_path(&self, name: &str, spec: &ToolSpec) -> PathBuf {
spec.path.as_ref().unwrap_or(&self.path).join(name)
}

pub fn update_tool(&mut self, raw: &mut Document, name: &str, spec: &ToolSpec) -> EmptyResult {
let mut root = raw.as_mut().make_mapping();

Expand Down
Loading

0 comments on commit 01a9e56

Please sign in to comment.