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 |
39 PlsCommand::ReinstallAll => vendor.1[2].to_owned(),
40 PlsCommand::Remove => vendor.1[3].to_owned(),
41 PlsCommand::Upgrade => vendor.1[4].to_owned(),
42 PlsCommand::Info => vendor.1[6].to_owned(),
43 PlsCommand::Update => vendor.1[7].to_owned(),
44 PlsCommand::UpgradeAll => vendor.1[8].to_owned(),
45 PlsCommand::Move { origin, destination } =>
46 format!("move from {} to {}", origin, destination),
47 PlsCommand::Search => {
48 if let Some(pager) = pager {
49 format!("{} | {}", vendor.1[5], pager)
50 } else {
51 vendor.1[5].to_owned()
52 }
53 }
54 PlsCommand::List => {
55 if let Some(pager) = pager {
56 format!("{} | {}", vendor.1[9], pager)
57 } else {
58 vendor.1[9].to_owned()
59 }
60 }
61 }
62 .replace("$yes", if yes {vendor.1[1]} else {""})
63 .replace("$args", &args)
64 }
65}