aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/dependency_resolver/operation/uninstall_operation.rs
blob: 138a8c8f3f1ea1c594532ceed689d5dade799166 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//! ref: composer/src/Composer/DependencyResolver/Operation/UninstallOperation.php

use crate::dependency_resolver::operation::operation_interface::OperationInterface;
use crate::dependency_resolver::operation::solver_operation::SolverOperation;
use crate::package::package_interface::PackageInterface;

#[derive(Debug)]
pub struct UninstallOperation {
    pub(crate) package: Box<dyn PackageInterface>,
}

impl UninstallOperation {
    pub fn new(package: Box<dyn PackageInterface>) -> Self {
        Self { package }
    }

    pub fn get_package(&self) -> &dyn PackageInterface {
        self.package.as_ref()
    }

    pub fn format(package: &dyn PackageInterface, _lock: bool) -> String {
        format!(
            "Removing <info>{}</info> (<comment>{}</comment>)",
            package.get_pretty_name(),
            package
                .get_full_pretty_version(true, <dyn PackageInterface>::DISPLAY_SOURCE_REF_IF_DEV),
        )
    }
}

impl SolverOperation for UninstallOperation {
    const TYPE: &'static str = "uninstall";
}

impl OperationInterface for UninstallOperation {
    fn get_operation_type(&self) -> String {
        Self::TYPE.to_string()
    }

    fn show(&self, lock: bool) -> String {
        Self::format(self.package.as_ref(), lock)
    }

    fn to_string(&self) -> String {
        self.show(true)
    }
}