please_install/
pls_command.rs1use crate::package::Package;
2use crate::vendor_data::VendorData;
3use crate::Vendor;
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq)]
6pub enum PlsCommand {
7 Install,
8 ReinstallAll,
9 Remove,
10 Upgrade,
11 Search,
12 Info,
13 Update,
14 UpgradeAll,
15 List,
16 Move {
17 origin: Vendor,
18 destination: Vendor,
19 },
20}
21
22impl PlsCommand {
23 pub fn format(self, vendor: VendorData, args: &Vec<Package>, yes: bool, pager: &Option<String>) -> String {
24 let args = match self {
25 PlsCommand::Remove |
26 PlsCommand::Info => args.iter()
27 .map(|arg| arg.name.clone())
28 .collect::<Vec<String>>()
29 .join(" "),
30
31 _ => args.iter()
32 .map(|arg| arg.to_string())
33 .collect::<Vec<String>>()
34 .join(" "),
35 };
36
37 match self {
38 PlsCommand::Install => vendor.1[2].to_owned(),
39 PlsCommand::ReinstallAll => vendor.1[4].to_owned(),
40 PlsCommand::Remove => vendor.1[3].to_owned(),
41 PlsCommand::Upgrade => vendor.1[4].to_owned(),
42 PlsCommand::Info => if let Some(pager) = pager {
43 format!("{} | {}", vendor.1[6], pager)
44 } else {
45 vendor.1[6].to_owned()
46 },
47 PlsCommand::Update => vendor.1[7].to_owned(),
48 PlsCommand::UpgradeAll => vendor.1[8].to_owned(),
49 PlsCommand::Move { origin, destination } =>
50 format!("move from {} to {}", origin, destination),
51 PlsCommand::Search => {
52 if let Some(pager) = pager {
53 format!("{} | {}", vendor.1[5], pager)
54 } else {
55 vendor.1[5].to_owned()
56 }
57 }
58 PlsCommand::List => {
59 if let Some(pager) = pager {
60 format!("{} | {}", vendor.1[9], pager)
61 } else {
62 vendor.1[9].to_owned()
63 }
64 }
65 }
66 .replace("$yes", if yes {vendor.1[1]} else {""})
67 .replace("$args", &args)
68 }
69
70 pub fn support_pager(&self) -> bool {
71 match self {
72 PlsCommand::Info |
73 PlsCommand::Move { .. } |
74 PlsCommand::Search |
75 PlsCommand::List => true,
76 _ => false,
77 }
78 }
79}