Skip to content

Commit a015247

Browse files
feat(scopes): add "all" keyword as alias for all available scopes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent cd724db commit a015247

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

src/scopes.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ pub fn expand_aliases(input: &str, all_scopes: &[String], sandbox: bool) -> Vec<
7575
&lower
7676
};
7777

78+
// "all" is a special alias that expands to every available scope
79+
if key == "all" {
80+
result.extend(all_scopes.iter().cloned());
81+
continue;
82+
}
83+
7884
if let Some(&prod_domain) = registry.get(key.as_str()) {
7985
let domain = if sandbox {
8086
format!("test.{}", prod_domain)
@@ -174,3 +180,38 @@ pub fn list_aliases() -> Vec<&'static str> {
174180
aliases.sort();
175181
aliases
176182
}
183+
184+
#[cfg(test)]
185+
mod tests {
186+
use super::*;
187+
188+
fn sample_scopes() -> Vec<String> {
189+
vec![
190+
"GET:sms.openapi.com/v1/send".to_string(),
191+
"POST:sms.openapi.com/v1/send".to_string(),
192+
"GET:company.openapi.com/v1/search".to_string(),
193+
]
194+
}
195+
196+
#[test]
197+
fn test_all_expands_to_every_scope() {
198+
let scopes = sample_scopes();
199+
let result = expand_aliases("all", &scopes, false);
200+
assert_eq!(result, scopes);
201+
}
202+
203+
#[test]
204+
fn test_all_case_insensitive() {
205+
let scopes = sample_scopes();
206+
let result = expand_aliases("ALL", &scopes, false);
207+
assert_eq!(result, scopes);
208+
}
209+
210+
#[test]
211+
fn test_all_mixed_with_other_aliases() {
212+
let scopes = sample_scopes();
213+
// "all" alone should still return everything without duplicates from mixing
214+
let result = expand_aliases("all", &scopes, false);
215+
assert_eq!(result.len(), scopes.len());
216+
}
217+
}

0 commit comments

Comments
 (0)