aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/command/prohibits_command.rs
blob: 6add1260fc09d7d2098900fe936cb50e77861beb (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! ref: composer/src/Composer/Command/ProhibitsCommand.php

use shirabe_external_packages::symfony::component::console::command::command::Command;
use shirabe_external_packages::symfony::component::console::command::command::CommandBase;

use crate::command::base_command::BaseCommand;
use crate::command::base_dependency_command::BaseDependencyCommand;
use crate::command::completion_trait::CompletionTrait;
use crate::composer::Composer;
use crate::console::input::input_argument::InputArgument;
use crate::console::input::input_option::InputOption;
use crate::io::io_interface::IOInterface;
use shirabe_external_packages::symfony::console::input::input_interface::InputInterface;
use shirabe_external_packages::symfony::console::output::output_interface::OutputInterface;

#[derive(Debug)]
pub struct ProhibitsCommand {
    inner: CommandBase,
    composer: Option<Composer>,
    io: Option<Box<dyn IOInterface>>,

    colors: Vec<String>,
}

impl CompletionTrait for ProhibitsCommand {
    fn require_composer(
        &self,
        disable_plugins: Option<bool>,
        disable_scripts: Option<bool>,
    ) -> Composer {
        todo!()
    }
}

impl ProhibitsCommand {
    pub fn configure(&mut self) {
        let package_suggestions = self.suggest_available_package();
        self.inner
            .set_name("prohibits")
            .set_aliases(vec!["why-not".to_string()])
            .set_description("Shows which packages prevent the given package from being installed")
            .set_definition(vec![
                InputArgument::new(
                    BaseDependencyCommand::ARGUMENT_PACKAGE,
                    InputArgument::REQUIRED,
                    "Package to inspect",
                    None,
                    package_suggestions,
                ),
                InputArgument::new(
                    BaseDependencyCommand::ARGUMENT_CONSTRAINT,
                    InputArgument::REQUIRED,
                    "Version constraint, which version you expected to be installed",
                    None,
                    None,
                ),
                InputOption::new(
                    BaseDependencyCommand::OPTION_RECURSIVE,
                    Some("r"),
                    InputOption::VALUE_NONE,
                    "Recursively resolves up to the root package",
                ),
                InputOption::new(
                    BaseDependencyCommand::OPTION_TREE,
                    Some("t"),
                    InputOption::VALUE_NONE,
                    "Prints the results as a nested tree",
                ),
                InputOption::new(
                    "locked",
                    None,
                    InputOption::VALUE_NONE,
                    "Read dependency information from composer.lock",
                ),
            ])
            .set_help(
                "Displays detailed information about why a package cannot be installed.\n\n\
                <info>php composer.phar prohibits composer/composer</info>\n\n\
                Read more at https://getcomposer.org/doc/03-cli.md#prohibits-why-not",
            );
    }

    pub fn execute(&self, input: &dyn InputInterface, output: &dyn OutputInterface) -> i64 {
        self.inner.do_execute(input, output, true)
    }
}

impl BaseCommand for ProhibitsCommand {
    fn inner(&self) -> &CommandBase {
        &self.inner
    }

    fn inner_mut(&mut self) -> &mut CommandBase {
        &mut self.inner
    }

    fn composer(&self) -> Option<&Composer> {
        self.composer.as_ref()
    }

    fn composer_mut(&mut self) -> &mut Option<Composer> {
        &mut self.composer
    }

    fn io(&self) -> Option<&dyn IOInterface> {
        self.io.as_deref()
    }

    fn io_mut(&mut self) -> &mut Option<Box<dyn IOInterface>> {
        &mut self.io
    }
}

impl BaseDependencyCommand for ProhibitsCommand {
    fn colors(&self) -> &[String] {
        &self.colors
    }

    fn colors_mut(&mut self) -> &mut [String] {
        &mut self.colors
    }
}

impl Command for ProhibitsCommand {}