fix(core): Make sure project paths are always absolute
This commit is contained in:
parent
04edeb9216
commit
b59d47a769
11
src/main.rs
11
src/main.rs
@ -2,9 +2,9 @@ mod dirs;
|
||||
mod tui;
|
||||
|
||||
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::{fs, path};
|
||||
|
||||
use anyhow::{ensure, Result};
|
||||
use clap::{Parser, Subcommand};
|
||||
@ -118,9 +118,9 @@ fn print_shell_integration(shell: &ShellType) {
|
||||
|
||||
fn add_project<P>(projects: &mut Projects, path: P) -> Result<()>
|
||||
where
|
||||
P: Into<PathBuf>,
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let path = path.into();
|
||||
let path = path::absolute(path)?;
|
||||
|
||||
ensure!(path.is_dir(), "Project path does not exists");
|
||||
ensure!(
|
||||
@ -130,6 +130,7 @@ where
|
||||
|
||||
projects.list.push(path);
|
||||
write_projects_file(projects)?;
|
||||
println!("Added {}", projects.list.last().unwrap().display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -139,7 +140,7 @@ fn remove_project<P>(projects: &mut Projects, path: P) -> Result<()>
|
||||
where
|
||||
P: AsRef<Path>,
|
||||
{
|
||||
let path = path.as_ref();
|
||||
let path = path::absolute(path)?;
|
||||
|
||||
ensure!(
|
||||
projects.list.contains(&path.to_path_buf()),
|
||||
@ -149,7 +150,7 @@ where
|
||||
let idx =
|
||||
projects.list.iter().enumerate().find_map(
|
||||
|(idx, elem)| {
|
||||
if elem == path {
|
||||
if elem == &path {
|
||||
Some(idx)
|
||||
} else {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user