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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
use clap::{ArgAction, Parser};
use crossterm::{
cursor,
style::Stylize,
terminal::{Clear, ClearType},
ExecutableCommand,
};
use scoop_rs::{operation, Event, Session, SyncOption};
use crate::{cui, flavor, util, Result};
/// Upgrade installed package(s)
#[derive(Debug, Parser)]
pub struct Args {
/// The package(s) to be upgraded (default: all except held)
#[arg(action = ArgAction::Append)]
package: Vec<String>,
/// Ignore failures to ensure a complete transaction
#[arg(short = 'f', long, action = ArgAction::SetTrue)]
ignore_failure: bool,
/// Leverage cache and suppress network access
#[arg(short = 'o', long, action = ArgAction::SetTrue)]
offline: bool,
/// Assume yes to all prompts and run non-interactively
#[arg(short = 'y', long, action = ArgAction::SetTrue)]
assume_yes: bool,
/// Escape hold to allow to upgrade held package(s)
#[arg(short = 'S', long, action = ArgAction::SetTrue)]
escape_hold: bool,
/// Skip package integrity check
#[arg(long, action = ArgAction::SetTrue)]
no_hash_check: bool,
/// Upgrade globally installed app(s) (requires admin rights)
#[arg(short = 'g', long, action = ArgAction::SetTrue)]
global: bool,
/// Target architecture (32bit, 64bit or arm64; default: host arch)
#[arg(long)]
arch: Option<String>,
}
pub fn execute(args: Args, session: &Session) -> Result<()> {
crate::util::apply_global_flag(args.global, session)?;
crate::util::apply_arch_flag(args.arch.as_deref())?;
let mut queries = args.package.iter().map(|s| s.as_str()).collect::<Vec<_>>();
if queries.is_empty() {
queries.push("*");
}
let mut options = vec![SyncOption::OnlyUpgrade];
if args.assume_yes {
options.push(SyncOption::AssumeYes);
}
if args.escape_hold {
options.push(SyncOption::EscapeHold);
}
if args.ignore_failure {
options.push(SyncOption::IgnoreFailure);
}
if args.offline {
options.push(SyncOption::Offline);
}
if args.no_hash_check {
options.push(SyncOption::NoHashCheck);
}
let rx = session.event_bus().receiver();
let tx = session.event_bus().sender();
let show_manifest = session.config().show_manifest();
let mut stdout = std::io::stdout();
let _ = stdout.execute(cursor::Hide);
let mut dlprogress = cui::MultiProgressUI::new();
let handle = std::thread::spawn(move || {
while let Ok(event) = rx.recv() {
match event {
Event::PackageResolveStart => println!("{}", flavor::progress("resolve")),
Event::PackageRunningSkipped { name, processes } => {
println!("Skipping '{name}' (running: {processes}). Quit it and retry to include it.");
}
Event::PackageDownloadSizingStart => println!("{}", flavor::progress("sizing")),
Event::PackageDownloadStart => println!("{}", flavor::progress("download")),
Event::PackageDownloadProgress(ctx) => {
let ident = ctx.ident.to_owned();
let url = ctx.url.to_owned();
let filename = ctx.filename.to_owned();
let dltotal = ctx.dltotal;
let dlnow = ctx.dlnow;
dlprogress.update(ident, url, filename, dltotal, dlnow);
}
Event::PackageDownloadDone => {}
Event::PackageIntegrityCheckStart => {
println!("{}", flavor::progress("integrity"))
}
Event::PackageIntegrityCheckProgress(ctx) => {
let mut stdout = std::io::stdout();
stdout
.execute(cursor::MoveToPreviousLine(1))
.unwrap()
.execute(Clear(ClearType::CurrentLine))
.unwrap();
println!("{}{}", flavor::progress("integrity"), ctx.dark_grey());
}
Event::PackageIntegrityCheckDone => {
let mut stdout = std::io::stdout();
stdout
.execute(cursor::MoveToPreviousLine(1))
.unwrap()
.execute(Clear(ClearType::CurrentLine))
.unwrap();
println!("{}{}", flavor::progress("integrity"), "Ok".green());
}
Event::PromptTransactionNeedConfirm(transaction) => {
if show_manifest {
cui::show_manifests(&transaction);
}
if let Some(install) = transaction.install_view() {
println!("The following packages will be INSTALLED:");
let output = install
.iter()
.map(|p| {
format!(
"{}{}{}",
p.ident(),
"-".dark_grey(),
p.version().dark_grey(),
)
})
.collect::<Vec<_>>()
.join(" ");
println!(" {}", output);
}
if let Some(upgrade) = transaction.upgrade_view() {
if transaction.install_view().is_some() {
println!();
}
println!("The following packages will be UPGRADED:");
let output = upgrade
.iter()
.map(|p| {
format!(
"{}{}{}",
p.ident(),
"-".dark_grey(),
p.upgradable_version().unwrap().dark_grey(),
)
})
.collect::<Vec<_>>()
.join(" ");
println!(" {}", output);
}
if let Some(replace) = transaction.replace_view() {
if transaction.install_view().is_some()
|| transaction.upgrade_view().is_some()
{
println!();
}
println!("The following packages will be REPLACED:");
let output = replace
.iter()
.map(|p| {
format!(
"{}{}/{}",
p.installed_bucket().unwrap().dark_grey().crossed_out(),
p.bucket(),
p.name(),
)
})
.collect::<Vec<_>>()
.join(" ");
println!(" {}", output);
}
if let Some(download_size) = transaction.download_size() {
let out = util::humansize(download_size.total, true);
if download_size.total > 0 {
if download_size.estimated {
println!(
"\nTotal download size: {} {}",
out,
"(estimated)".dark_grey()
);
} else {
println!("\nTotal download size: {}", out);
}
} else {
println!("\n{}", flavor::progress("cached"));
}
}
let mut stdout = std::io::stdout();
let _ = stdout.execute(cursor::Show);
let answer = cui::prompt_yes_no();
let _ = tx.send(Event::PromptTransactionNeedConfirmResult(answer));
let _ = stdout.execute(cursor::Hide);
}
Event::PackageInstalledNotes {
ident,
notes,
suggest,
} => {
if !notes.is_empty() {
println!("\nNotes for {}:", ident);
for note in ¬es {
println!(" {}", note);
}
}
if !suggest.is_empty() {
println!("Suggestions for {}:", ident);
for entry in &suggest {
println!(" {}", entry);
}
}
}
Event::PackageSyncDone => break,
_ => {}
}
}
});
operation::package_sync(session, queries, options)?;
handle.join().unwrap();
let _ = stdout.execute(cursor::Show);
Ok(())
}