cli : add /glob command (#21084)

* add /glob command

* output error when max files reached

* support globbing outside curdir
This commit is contained in:
Sigbjørn Skjæret 2026-03-28 02:33:04 +01:00 committed by GitHub
parent bf934f28db
commit c46758d28f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 114 additions and 49 deletions

View file

@ -101,38 +101,6 @@ static run_proc_result run_process(
return res;
}
// simple glob: * matches non-/ chars, ** matches anything including /
static bool glob_match(const char * pattern, const char * str) {
if (*pattern == '\0') {
return *str == '\0';
}
if (pattern[0] == '*' && pattern[1] == '*') {
const char * p = pattern + 2;
if (*p == '/') p++;
if (glob_match(p, str)) return true;
if (*str != '\0') return glob_match(pattern, str + 1);
return false;
}
if (*pattern == '*') {
const char * p = pattern + 1;
for (; *str != '\0' && *str != '/'; str++) {
if (glob_match(p, str)) return true;
}
return glob_match(p, str);
}
if (*pattern == '?' && *str != '\0' && *str != '/') {
return glob_match(pattern + 1, str + 1);
}
if (*pattern == *str) {
return glob_match(pattern + 1, str + 1);
}
return false;
}
static bool glob_match(const std::string & pattern, const std::string & str) {
return glob_match(pattern.c_str(), str.c_str());
}
json server_tool::to_json() {
return {
{"display_name", display_name},