mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-25 19:22:01 +03:00
Implement remove imported package
This commit is contained in:
parent
db997ac90a
commit
1ab7c49e72
@ -46,4 +46,20 @@ impl ImportsDirectory {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Removes an imported package in the imports directory at the provided path.
|
||||
pub fn remove_import(path: &PathBuf, package_name: &str) -> Result<(), ImportsDirectoryError> {
|
||||
let mut path = path.to_owned();
|
||||
if path.is_dir() && !path.ends_with(IMPORTS_DIRECTORY_NAME) {
|
||||
path.push(PathBuf::from(IMPORTS_DIRECTORY_NAME));
|
||||
}
|
||||
|
||||
path.push(PathBuf::from(package_name));
|
||||
|
||||
if path.is_dir() && path.exists() {
|
||||
fs::remove_dir_all(&path).map_err(ImportsDirectoryError::Removing)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,9 @@ impl LeoPackage {
|
||||
pub fn initialize(package_name: &str, is_lib: bool, path: &PathBuf) -> Result<(), PackageError> {
|
||||
package::Package::initialize(package_name, is_lib, path)
|
||||
}
|
||||
|
||||
/// Removes an imported Leo package
|
||||
pub fn remove_imported_package(package_name: &str, path: &PathBuf) -> Result<(), PackageError> {
|
||||
package::Package::remove_imported_package(package_name, path)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,22 @@
|
||||
// Copyright (C) 2019-2020 Aleo Systems Inc.
|
||||
// This file is part of the Leo library.
|
||||
|
||||
// The Leo library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// The Leo library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{
|
||||
errors::PackageError,
|
||||
imports::ImportsDirectory,
|
||||
inputs::{InputFile, InputsDirectory, StateFile},
|
||||
root::{Gitignore, Manifest, README},
|
||||
source::{LibraryFile, MainFile, SourceDirectory},
|
||||
@ -167,7 +184,7 @@ impl Package {
|
||||
}
|
||||
|
||||
/// Removes the package at the given path
|
||||
pub fn remove_package(_package_name: &str) -> Result<(), PackageError> {
|
||||
unimplemented!()
|
||||
pub fn remove_imported_package(package_name: &str, path: &PathBuf) -> Result<(), PackageError> {
|
||||
Ok(ImportsDirectory::remove_import(path, package_name)?)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user