diff --git a/.github/workflows/ci.yml b/.github/workflows/release.yml similarity index 94% rename from .github/workflows/ci.yml rename to .github/workflows/release.yml index 5117cda..f0de5a0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/release.yml @@ -17,7 +17,7 @@ jobs: include: - label: x86_64-pc-windows-msvc-portable target: x86_64-pc-windows-msvc - bins: --bin pvm + bins: --bin pyvm os: windows features: rustflags: @@ -43,7 +43,7 @@ jobs: with: name: ${{matrix.label}} path: | - target/${{matrix.target}}/release/pvm.exe + target/${{matrix.target}}/release/pyvm.exe test: runs-on: ${{ matrix.os }}-latest @@ -93,7 +93,7 @@ jobs: run: | mkdir public cd target/x86_64-pc-windows-msvc-portable - zip -r ../../public/pvm-${{ env.VERSION }}-x86_64-pc-windows-msvc-portable.zip . + zip -r ../../public/pyvm-${{ env.VERSION }}-x86_64-pc-windows-msvc-portable.zip . cd ../.. - uses: actions/upload-artifact@v3 with: diff --git a/src/cmd_add.rs b/src/cmd_add.rs index 18ece1f..b9c0879 100644 --- a/src/cmd_add.rs +++ b/src/cmd_add.rs @@ -1,5 +1,3 @@ -use anyhow::anyhow; - use crate::get_venv_path; use std::process::{Command, Stdio}; @@ -9,7 +7,7 @@ pub fn exec(name: &str, version: Option, force: bool) -> anyhow::Result< let path = get_venv_path()?.join(name); if path.is_file() || (path.is_dir() && !force) { - return Err(anyhow!("Env with the same name `{name}` exists.")); + anyhow::bail!("Env with the same name `{name}` exists."); } let mut cmd = &mut Command::new(VENV_EXE); @@ -26,10 +24,10 @@ pub fn exec(name: &str, version: Option, force: bool) -> anyhow::Result< .stderr(Stdio::inherit()) .output() { - return Err(anyhow!( + anyhow::bail!( "Failed to create env `{name}`: {e}\nMaybe `{}` is not in PATH?", VENV_EXE - )); + ); }; #[cfg(target_family = "windows")] diff --git a/src/cmd_export.rs b/src/cmd_export.rs index 3568df9..17de8cc 100644 --- a/src/cmd_export.rs +++ b/src/cmd_export.rs @@ -1,5 +1,3 @@ -use anyhow::anyhow; - use crate::consts::PY_BIN_DIR; use crate::get_venv_path; use crate::manifest::{Env, EnvManifest}; @@ -19,7 +17,7 @@ pub fn exec(output: Option) -> anyhow::Result<()> { let s = export_library()?; let outpath = output.unwrap_or(export_filename()); if fs::write(&outpath, s).is_err() { - return Err(anyhow!("failed to write manifest.")); + anyhow::bail!("failed to write manifest."); } println!("manifest has been written at {}", outpath); @@ -29,13 +27,7 @@ pub fn exec(output: Option) -> anyhow::Result<()> { fn export_library() -> anyhow::Result { let venv_path = get_venv_path()?; - let sep = if cfg!(windows) { - "\r\n" - } else if cfg!(darwin) { - "\r" - } else { - "\n" - }; + let sep = if cfg!(windows) { "\r\n" } else { "\n" }; let mut pipe = vec![]; for path in read_dir(&venv_path)? { diff --git a/src/cmd_remove.rs b/src/cmd_remove.rs index b8b65d7..66a2462 100644 --- a/src/cmd_remove.rs +++ b/src/cmd_remove.rs @@ -1,5 +1,3 @@ -use anyhow::anyhow; - use crate::get_venv_path; use crate::utils::is_valid_env; use std::fs; @@ -7,19 +5,19 @@ use std::fs; pub fn exec(name: &str) -> anyhow::Result<()> { let path = get_venv_path()?.join(name); if !path.exists() { - return Err(anyhow!("No env `{name}` exists.")); + anyhow::bail!("No env `{name}` exists."); } if path.is_file() { - return Err(anyhow!("File with the same name `{name}` exists.")); + anyhow::bail!("File with the same name `{name}` exists."); } if !is_valid_env(&path) { - return Err(anyhow!("Invalid env `{name}`")); + anyhow::bail!("Invalid env `{name}`"); } if fs::remove_dir_all(path).is_err() { - return Err(anyhow!("Failed to remove `{name}`")); + anyhow::bail!("Failed to remove `{name}`"); } println!("Removed env `{name}`"); diff --git a/src/cmd_use.rs b/src/cmd_use.rs index 2c7445e..4084e2f 100644 --- a/src/cmd_use.rs +++ b/src/cmd_use.rs @@ -1,5 +1,3 @@ -use anyhow::anyhow; - use crate::get_venv_path; use crate::utils::is_valid_env; @@ -7,11 +5,11 @@ pub fn exec(name: &str) -> anyhow::Result<()> { let path = get_venv_path()?.join(name); if !path.exists() { - return Err(anyhow!("No env `{name}` exists.")); + anyhow::bail!("No env `{name}` exists."); } if !is_valid_env(&path) { - return Err(anyhow!("Invalid env `{name}`")); + anyhow::bail!("Invalid env `{name}`"); } #[cfg(target_family = "windows")] @@ -24,7 +22,7 @@ pub fn exec(name: &str) -> anyhow::Result<()> { .arg(path.join("Scripts/activate.bat")) .status() { - return Err(anyhow!("Failed to activate env `{name}`:\n{e}")); + anyhow::bail!("Failed to activate env `{name}`:\n{e}"); } } diff --git a/src/utils.rs b/src/utils.rs index 3d5b1e9..f460b68 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,7 +1,6 @@ use crate::consts::PYTHON_VENV_PATH; use crate::consts::PY_BIN_DIR; use crate::consts::PY_VENV_CFG; -use anyhow::anyhow; use std::path::{Path, PathBuf}; pub fn is_valid_env(path: impl AsRef) -> bool { @@ -11,9 +10,6 @@ pub fn is_valid_env(path: impl AsRef) -> bool { } pub(super) fn get_venv_path() -> anyhow::Result { - if let Some(home) = homedir::get_my_home()? { - Ok(home.join(PYTHON_VENV_PATH)) - } else { - Err(anyhow!("failed to get HOME dir")) - } + let home = homedir::get_my_home()?.ok_or(anyhow::anyhow!("failed to get HOME dir"))?; + Ok(home.join(PYTHON_VENV_PATH)) }