mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-12-26 11:45:00 +03:00
Implement leo remove functionality
This commit is contained in:
parent
1ab7c49e72
commit
f7466f4264
@ -14,37 +14,35 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// 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/>.
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
use crate::{
|
use crate::{cli::*, cli_types::*, errors::CLIError};
|
||||||
cli::*,
|
use leo_package::LeoPackage;
|
||||||
cli_types::*,
|
|
||||||
commands::BuildCommand,
|
|
||||||
errors::{CLIError, RunError},
|
|
||||||
};
|
|
||||||
use leo_package::{
|
|
||||||
root::Manifest,
|
|
||||||
source::{MAIN_FILENAME, SOURCE_DIRECTORY_NAME},
|
|
||||||
};
|
|
||||||
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use std::{convert::TryFrom, env::current_dir};
|
use std::env::current_dir;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct RemoveCommand;
|
pub struct RemoveCommand;
|
||||||
|
|
||||||
impl CLI for RemoveCommand {
|
impl CLI for RemoveCommand {
|
||||||
type Options = ();
|
type Options = Option<String>;
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
const ABOUT: AboutType = "Uninstall a package from the current package (*)";
|
const ABOUT: AboutType = "Uninstall a package from the current package";
|
||||||
const ARGUMENTS: &'static [ArgumentType] = &[];
|
const ARGUMENTS: &'static [ArgumentType] = &[
|
||||||
|
// (name, description, required, index)
|
||||||
|
("NAME", "Removes the package from the current directory", true, 1u64),
|
||||||
|
];
|
||||||
const FLAGS: &'static [FlagType] = &[];
|
const FLAGS: &'static [FlagType] = &[];
|
||||||
const NAME: NameType = "remove";
|
const NAME: NameType = "remove";
|
||||||
const OPTIONS: &'static [OptionType] = &[];
|
const OPTIONS: &'static [OptionType] = &[];
|
||||||
const SUBCOMMANDS: &'static [SubCommandType] = &[];
|
const SUBCOMMANDS: &'static [SubCommandType] = &[];
|
||||||
|
|
||||||
#[cfg_attr(tarpaulin, skip)]
|
#[cfg_attr(tarpaulin, skip)]
|
||||||
fn parse(_arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
|
fn parse(arguments: &ArgMatches) -> Result<Self::Options, CLIError> {
|
||||||
Ok(())
|
Ok(match arguments.value_of("NAME") {
|
||||||
|
Some(name) => Some(name.to_string()),
|
||||||
|
None => unreachable!(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(tarpaulin, skip)]
|
#[cfg_attr(tarpaulin, skip)]
|
||||||
@ -55,24 +53,11 @@ impl CLI for RemoveCommand {
|
|||||||
|
|
||||||
let path = current_dir()?;
|
let path = current_dir()?;
|
||||||
|
|
||||||
match BuildCommand::output(options)? {
|
if let Some(package_name) = options {
|
||||||
Some((_program, _checksum_differs)) => {
|
LeoPackage::remove_imported_package(&package_name, &path)?;
|
||||||
// Get the package name
|
tracing::info!("Successfully removed package \"{}\"\n", package_name);
|
||||||
let _package_name = Manifest::try_from(&path)?.get_package_name();
|
|
||||||
|
|
||||||
tracing::info!("Unimplemented - `leo remove`");
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
let mut main_file_path = path.clone();
|
|
||||||
main_file_path.push(SOURCE_DIRECTORY_NAME);
|
|
||||||
main_file_path.push(MAIN_FILENAME);
|
|
||||||
|
|
||||||
Err(CLIError::RunError(RunError::MainFileDoesNotExist(
|
|
||||||
main_file_path.into_os_string(),
|
|
||||||
)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,9 @@ pub enum ImportsDirectoryError {
|
|||||||
#[error("file {:?} type getting: {}", _0, _1)]
|
#[error("file {:?} type getting: {}", _0, _1)]
|
||||||
GettingFileType(OsString, io::Error),
|
GettingFileType(OsString, io::Error),
|
||||||
|
|
||||||
|
#[error("package {:?} does not exist as an import", _0)]
|
||||||
|
ImportDoesNotExist(OsString),
|
||||||
|
|
||||||
#[error("invalid file {:?} extension: {:?}", _0, _1)]
|
#[error("invalid file {:?} extension: {:?}", _0, _1)]
|
||||||
InvalidFileExtension(OsString, OsString),
|
InvalidFileExtension(OsString, OsString),
|
||||||
|
|
||||||
|
@ -56,10 +56,12 @@ impl ImportsDirectory {
|
|||||||
|
|
||||||
path.push(PathBuf::from(package_name));
|
path.push(PathBuf::from(package_name));
|
||||||
|
|
||||||
if path.is_dir() && path.exists() {
|
if !path.exists() || !path.is_dir() {
|
||||||
fs::remove_dir_all(&path).map_err(ImportsDirectoryError::Removing)?;
|
return Err(ImportsDirectoryError::ImportDoesNotExist(package_name.into()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fs::remove_dir_all(&path).map_err(ImportsDirectoryError::Removing)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user