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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
//! Scoop package index fetcher (Windows).
//!
//! Fetches package metadata from Scoop buckets (main, extras, versions).
//!
//! ## API Strategy
//! - **fetch**: GitHub raw bucket manifests
//! - **fetch_versions**: Same API, single version
//! - **search**: `scoop.sh/api/apps?q=`
//! - **fetch_all**: Not supported (no bulk API)
//!
//! ## Multi-bucket Support
//! ```rust,ignore
//! use normalize_packages::index::scoop::{Scoop, ScoopBucket};
//!
//! // All buckets (default)
//! let all = Scoop::all();
//!
//! // Main + Extras only
//! let core = Scoop::core();
//!
//! // Main bucket only
//! let main = Scoop::main_only();
//! ```
use super::{IndexError, PackageIndex, PackageMeta, VersionMeta};
use std::collections::HashMap;
/// Available Scoop buckets.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ScoopBucket {
/// Main bucket - essential apps
Main,
/// Extras - additional apps including GUI apps
Extras,
/// Versions - old versions of apps
Versions,
/// Games
Games,
/// Nerd Fonts
NerdFonts,
/// Java - JDKs and Java tools
Java,
/// PHP versions
Php,
/// Nonportable - apps requiring special install
Nonportable,
}
impl ScoopBucket {
/// Get the GitHub repo path for this bucket.
fn repo_path(&self) -> &'static str {
match self {
Self::Main => "ScoopInstaller/Main/master/bucket",
Self::Extras => "ScoopInstaller/Extras/master/bucket",
Self::Versions => "ScoopInstaller/Versions/master/bucket",
Self::Games => "Calinou/scoop-games/master/bucket",
Self::NerdFonts => "matthewjberger/scoop-nerd-fonts/master/bucket",
Self::Java => "ScoopInstaller/Java/master/bucket",
Self::Php => "ScoopInstaller/PHP/master/bucket",
Self::Nonportable => "ScoopInstaller/Nonportable/master/bucket",
}
}
/// Get the bucket name for tagging.
pub fn name(&self) -> &'static str {
match self {
Self::Main => "main",
Self::Extras => "extras",
Self::Versions => "versions",
Self::Games => "games",
Self::NerdFonts => "nerd-fonts",
Self::Java => "java",
Self::Php => "php",
Self::Nonportable => "nonportable",
}
}
/// All available buckets.
pub fn all() -> &'static [ScoopBucket] {
&[
Self::Main,
Self::Extras,
Self::Versions,
Self::Games,
Self::NerdFonts,
Self::Java,
Self::Php,
Self::Nonportable,
]
}
/// Core buckets (Main + Extras).
pub fn core() -> &'static [ScoopBucket] {
&[Self::Main, Self::Extras]
}
/// Main bucket only.
pub fn main() -> &'static [ScoopBucket] {
&[Self::Main]
}
/// Development-focused buckets.
pub fn dev() -> &'static [ScoopBucket] {
&[
Self::Main,
Self::Extras,
Self::Versions,
Self::Java,
Self::Php,
]
}
}
/// Scoop package index fetcher with configurable buckets.
pub struct Scoop {
buckets: Vec<ScoopBucket>,
}
impl Scoop {
/// Scoop search API.
const SCOOP_API: &'static str = "https://scoop.sh/api";
/// GitHub raw content for bucket manifests.
const GITHUB_RAW: &'static str = "https://raw.githubusercontent.com";
/// Create a fetcher with all buckets.
pub fn all() -> Self {
Self {
buckets: ScoopBucket::all().to_vec(),
}
}
/// Create a fetcher with core buckets (Main + Extras).
pub fn core() -> Self {
Self {
buckets: ScoopBucket::core().to_vec(),
}
}
/// Create a fetcher with main bucket only.
pub fn main_only() -> Self {
Self {
buckets: ScoopBucket::main().to_vec(),
}
}
/// Create a fetcher with development-focused buckets.
pub fn dev() -> Self {
Self {
buckets: ScoopBucket::dev().to_vec(),
}
}
/// Create a fetcher with custom bucket selection.
pub fn with_buckets(buckets: &[ScoopBucket]) -> Self {
Self {
buckets: buckets.to_vec(),
}
}
/// Fetch a package from a specific bucket.
fn fetch_from_bucket(name: &str, bucket: ScoopBucket) -> Result<PackageMeta, IndexError> {
let url = format!("{}/{}/{}.json", Self::GITHUB_RAW, bucket.repo_path(), name);
let response: serde_json::Value = ureq::get(&url).call()?.into_json()?;
let mut extra = HashMap::new();
extra.insert(
"source_repo".to_string(),
serde_json::Value::String(bucket.name().to_string()),
);
Ok(PackageMeta {
name: name.to_string(),
version: response["version"]
.as_str()
.unwrap_or("unknown")
.to_string(),
description: response["description"].as_str().map(String::from),
homepage: response["homepage"].as_str().map(String::from),
repository: response["repository"]
.as_str()
.or_else(|| response["checkver"]["github"].as_str())
.map(|s| {
if s.starts_with("http") {
s.to_string()
} else {
format!("https://github.com/{}", s)
}
}),
license: response["license"]
.as_str()
.or_else(|| response["license"]["identifier"].as_str())
.map(String::from),
binaries: response["bin"]
.as_array()
.map(|bins| {
bins.iter()
.filter_map(|b| {
b.as_str()
.or_else(|| b.as_array().and_then(|a| a.first()?.as_str()))
.map(|s| {
// Extract just the binary name from path
s.rsplit(['/', '\\']).next().unwrap_or(s).to_string()
})
})
.collect()
})
.unwrap_or_default(),
keywords: Vec::new(),
maintainers: Vec::new(),
published: None,
downloads: None,
archive_url: None,
checksum: None,
extra,
})
}
}
impl PackageIndex for Scoop {
fn ecosystem(&self) -> &'static str {
"scoop"
}
fn display_name(&self) -> &'static str {
"Scoop (Windows)"
}
fn fetch(&self, name: &str) -> Result<PackageMeta, IndexError> {
// Try each configured bucket until we find the package
for &bucket in &self.buckets {
match Self::fetch_from_bucket(name, bucket) {
Ok(pkg) => return Ok(pkg),
Err(IndexError::Network(_)) => continue,
Err(e) => return Err(e),
}
}
Err(IndexError::NotFound(name.to_string()))
}
fn fetch_versions(&self, name: &str) -> Result<Vec<VersionMeta>, IndexError> {
// Scoop manifests only contain current version
// Check all configured buckets for available versions
let mut versions = Vec::new();
for &bucket in &self.buckets {
if let Ok(pkg) = Self::fetch_from_bucket(name, bucket) {
versions.push(VersionMeta {
version: format!("{} ({})", pkg.version, bucket.name()),
released: None,
yanked: false,
});
}
}
if versions.is_empty() {
return Err(IndexError::NotFound(name.to_string()));
}
Ok(versions)
}
fn search(&self, query: &str) -> Result<Vec<PackageMeta>, IndexError> {
// Use the scoop.sh search API
let url = format!("{}/apps?q={}", Self::SCOOP_API, query);
let response: serde_json::Value = ureq::get(&url).call()?.into_json()?;
let apps = response
.as_array()
.ok_or_else(|| IndexError::Parse("expected array".into()))?;
// Filter to configured buckets
let bucket_names: Vec<_> = self.buckets.iter().map(|b| b.name()).collect();
Ok(apps
.iter()
.filter(|app| {
app["bucket"]
.as_str()
.map(|b| bucket_names.contains(&b))
.unwrap_or(true) // Include if no bucket specified
})
.filter_map(|app| {
let mut extra = HashMap::new();
if let Some(bucket) = app["bucket"].as_str() {
extra.insert(
"source_repo".to_string(),
serde_json::Value::String(bucket.to_string()),
);
}
Some(PackageMeta {
name: app["name"].as_str()?.to_string(),
version: app["version"].as_str().unwrap_or("unknown").to_string(),
description: app["description"].as_str().map(String::from),
homepage: app["homepage"].as_str().map(String::from),
repository: None,
license: app["license"].as_str().map(String::from),
binaries: Vec::new(),
keywords: Vec::new(),
maintainers: Vec::new(),
published: None,
downloads: None,
archive_url: None,
checksum: None,
extra,
})
})
.collect())
}
}