Skip to content

Commit

Permalink
lazy-load toml_edit (#1594)
Browse files Browse the repository at this point in the history
* lazy-load toml_edit

* Commit from GitHub Actions (test)

---------

Co-authored-by: mise[bot] <[email protected]>
  • Loading branch information
jdx and mise-en-dev authored Feb 2, 2024
1 parent 0eae892 commit ae658f8
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 102 deletions.
2 changes: 1 addition & 1 deletion src/cli/alias/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct AliasSet {
impl AliasSet {
pub fn run(self) -> Result<()> {
let mut global_config = Config::get().global_config()?;
global_config.set_alias(&self.plugin, &self.alias, &self.value);
global_config.set_alias(&self.plugin, &self.alias, &self.value)?;
global_config.save()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/alias/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct AliasUnset {
impl AliasUnset {
pub fn run(self) -> Result<()> {
let mut global_config = Config::get().global_config()?;
global_config.remove_alias(&self.plugin, &self.alias);
global_config.remove_alias(&self.plugin, &self.alias)?;
global_config.save()
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/cli/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub fn local(

if let Some(plugins) = &remove {
for plugin in plugins {
cf.remove_plugin(plugin);
cf.remove_plugin(plugin)?;
}
let tools = plugins
.iter()
Expand All @@ -128,7 +128,7 @@ pub fn local(
if !runtime.is_empty() || remove.is_some() {
cf.save()?;
} else {
miseprint!("{}", cf.dump());
miseprint!("{}", cf.dump()?);
}

Ok(())
Expand Down
8 changes: 5 additions & 3 deletions src/cli/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Set {

if let Some(env_names) = &self.remove {
for name in env_names {
mise_toml.remove_env(name);
mise_toml.remove_env(name)?;
}
}

Expand All @@ -83,7 +83,7 @@ impl Set {
}
for ev in env_vars {
match ev.value {
Some(value) => mise_toml.update_env(&ev.key, value),
Some(value) => mise_toml.update_env(&ev.key, value)?,
None => bail!("{} has no value", ev.key),
}
}
Expand Down Expand Up @@ -131,7 +131,7 @@ mod tests {

fn remove_config_file(filename: &str) -> PathBuf {
let cf_path = env::current_dir().unwrap().join(filename);
let _ = file::remove_file(&cf_path);
let _ = file::write(&cf_path, "");
cf_path
}

Expand All @@ -156,6 +156,7 @@ mod tests {
assert_cli_snapshot!("env-vars", "--file", filename, "FOO=bar", @"");
assert_snapshot!(file::read_to_string(cf_path).unwrap());
remove_config_file(filename);
file::remove_file(filename).unwrap();
}

#[test]
Expand All @@ -175,5 +176,6 @@ mod tests {
assert_cli_snapshot!("env-vars", "--file", filename, "--remove", "BAZ", @"");
assert_snapshot!(file::read_to_string(cf_path).unwrap());
remove_config_file(filename);
file::remove_file(filename).unwrap();
}
}
5 changes: 3 additions & 2 deletions src/cli/unset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Unset {
let mut mise_toml = get_mise_toml(&filename)?;

for name in self.keys.iter() {
mise_toml.remove_env(name);
mise_toml.remove_env(name)?;
}

mise_toml.save()
Expand All @@ -62,7 +62,7 @@ mod tests {

fn remove_config_file(filename: &str) -> PathBuf {
let cf_path = env::current_dir().unwrap().join(filename);
let _ = file::remove_file(&cf_path);
let _ = file::write(&cf_path, "");
cf_path
}

Expand All @@ -76,5 +76,6 @@ mod tests {
assert_cli_snapshot!("unset", "BAZ", @"");
assert_snapshot!(file::read_to_string(cf_path).unwrap());
remove_config_file(filename);
file::remove_file(filename).unwrap();
}
}
24 changes: 21 additions & 3 deletions src/cli/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ impl Use {
}
})
.collect();
cf.replace_versions(fa, &versions);
cf.replace_versions(fa, &versions)?;
}

if self.global {
self.warn_if_hidden(&config, cf.get_path());
}
for plugin_name in &self.remove {
cf.remove_plugin(plugin_name);
cf.remove_plugin(plugin_name)?;
}
cf.save()?;
self.render_success_message(cf.as_ref(), &versions);
Expand Down Expand Up @@ -264,13 +264,31 @@ mod tests {
fn test_use_global() {
let cf_path = dirs::CONFIG.join("config.toml");
let orig = file::read_to_string(&cf_path).unwrap();
let _ = file::remove_file(&cf_path);

assert_cli_snapshot!("use", "-g", "tiny@2", @r###"
mise ~/config/config.toml tools: [email protected]
mise tiny is defined in ~/cwd/.test-tool-versions which overrides the global config (~/config/config.toml)
"###);
assert_snapshot!(file::read_to_string(&cf_path).unwrap(), @r###"
[env]
TEST_ENV_VAR = 'test-123'
[alias.tiny]
"my/alias" = '3.0'
[tasks.configtask]
run = 'echo "configtask:"'
[tasks.lint]
run = 'echo "linting!"'
[tasks.test]
run = 'echo "testing!"'
[settings]
always_keep_download= true
always_keep_install= true
legacy_version_file= true
plugin_autoupdate_last_check_duration = "20m"
jobs = 2
[tools]
tiny = "2"
"###);
Expand Down
6 changes: 3 additions & 3 deletions src/config/config_file/legacy_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ impl ConfigFile for LegacyVersionFile {
self.path.as_path()
}

fn remove_plugin(&mut self, _fa: &ForgeArg) {
fn remove_plugin(&mut self, _fa: &ForgeArg) -> Result<()> {
unimplemented!()
}

fn replace_versions(&mut self, _plugin_name: &ForgeArg, _versions: &[String]) {
fn replace_versions(&mut self, _plugin_name: &ForgeArg, _versions: &[String]) -> Result<()> {
unimplemented!()
}

fn save(&self) -> Result<()> {
unimplemented!()
}

fn dump(&self) -> String {
fn dump(&self) -> Result<String> {
unimplemented!()
}

Expand Down
Loading

0 comments on commit ae658f8

Please sign in to comment.