Skip to content

Commit

Permalink
vavm to anchorversion
Browse files Browse the repository at this point in the history
  • Loading branch information
dromaz committed Jul 1, 2023
1 parent f70118c commit 4df64ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions avm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub fn uninstall_version(version: &Version) -> Result<()> {
}

/// Read version from .vavm
pub fn read_vavm_file() -> Result<Version> {
pub fn read_anchorversion_file() -> Result<Version> {
// get the root localisation
let path = env::current_dir().unwrap();
let dir_content = fs::read_dir(path).unwrap();
Expand All @@ -150,15 +150,15 @@ pub fn read_vavm_file() -> Result<Version> {
if path_entry
.file_name()
.unwrap()
.to_string_lossy() == ".vavm" {
.to_string_lossy() == ".anchorversion" {
let path_entry_content = fs::read_to_string(path_entry).unwrap();
let formated_content = path_entry_content.replace(|c: char| c.is_whitespace(), "");
let version = Version::parse(&formated_content).map_err(|e| anyhow!(e)).unwrap();
return Ok(version);
}
}

return Err(anyhow::format_err!("cannot find .vavm file"));
return Err(anyhow::format_err!(".anchorversion file not found. Please ensure the file exists in the current directory."));
}

/// Ensure the users home directory is setup with the paths required by AVM.
Expand Down Expand Up @@ -268,16 +268,16 @@ mod tests {
use std::io::Write;

#[test]
fn test_read_vavm() {
fn test_read_anchorversion() {
ensure_paths();
let mut dir = env::current_dir().unwrap();
dir.push(".vavm");
dir.push(".anchorversion");
let mut file_created = fs::File::create(&dir).unwrap();
let test_version = "0.26.0";
file_created.write(test_version.as_bytes()).unwrap();


let version = read_vavm_file();
let version = read_anchorversion_file();
match version {
Ok(v) => {
assert_eq!(v.to_string(), test_version);
Expand Down
6 changes: 3 additions & 3 deletions avm/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use anyhow::{Error, Result};
use avm::{read_vavm_file, use_version};
use avm::{read_anchorversion_file, use_version};
use clap::{Parser, Subcommand};
use semver::Version;

Expand Down Expand Up @@ -42,7 +42,7 @@ pub enum Commands {
fn _parse_option_version(version: Option<&str>) -> Result<Version, Error> {
match version {
Some(v) => parse_version(v),
None => read_vavm_file()
None => read_anchorversion_file()
}
}

Expand All @@ -60,7 +60,7 @@ pub fn entry(opts: Cli) -> Result<()> {
match version {
Some(v) => use_version(&v),
None => {
let version_from_vavm = read_vavm_file()?;
let version_from_vavm = read_anchorversion_file()?;
use_version(&version_from_vavm)
}
}
Expand Down

0 comments on commit 4df64ca

Please sign in to comment.