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;
|
mod tui;
|
||||||
|
|
||||||
|
|
||||||
use std::fs;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
use std::{fs, path};
|
||||||
|
|
||||||
use anyhow::{ensure, Result};
|
use anyhow::{ensure, Result};
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
@ -118,9 +118,9 @@ fn print_shell_integration(shell: &ShellType) {
|
|||||||
|
|
||||||
fn add_project<P>(projects: &mut Projects, path: P) -> Result<()>
|
fn add_project<P>(projects: &mut Projects, path: P) -> Result<()>
|
||||||
where
|
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!(path.is_dir(), "Project path does not exists");
|
||||||
ensure!(
|
ensure!(
|
||||||
@ -130,6 +130,7 @@ where
|
|||||||
|
|
||||||
projects.list.push(path);
|
projects.list.push(path);
|
||||||
write_projects_file(projects)?;
|
write_projects_file(projects)?;
|
||||||
|
println!("Added {}", projects.list.last().unwrap().display());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -139,7 +140,7 @@ fn remove_project<P>(projects: &mut Projects, path: P) -> Result<()>
|
|||||||
where
|
where
|
||||||
P: AsRef<Path>,
|
P: AsRef<Path>,
|
||||||
{
|
{
|
||||||
let path = path.as_ref();
|
let path = path::absolute(path)?;
|
||||||
|
|
||||||
ensure!(
|
ensure!(
|
||||||
projects.list.contains(&path.to_path_buf()),
|
projects.list.contains(&path.to_path_buf()),
|
||||||
@ -149,7 +150,7 @@ where
|
|||||||
let idx =
|
let idx =
|
||||||
projects.list.iter().enumerate().find_map(
|
projects.list.iter().enumerate().find_map(
|
||||||
|(idx, elem)| {
|
|(idx, elem)| {
|
||||||
if elem == path {
|
if elem == &path {
|
||||||
Some(idx)
|
Some(idx)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
Loading…
Reference in New Issue
Block a user