Add vitastor-cli ls --exact

This commit is contained in:
Vitaliy Filippov
2024-08-31 02:36:25 +03:00
parent 6a8daedbe2
commit 30eaa1a8e6
2 changed files with 6 additions and 3 deletions
+2 -1
View File
@@ -30,6 +30,7 @@ static const char* help_text =
"\n"
"vitastor-cli ls [-l] [-p POOL] [--sort FIELD] [-r] [-n N] [<glob> ...]\n"
" List images (only matching <glob> patterns if passed).\n"
" --exact Do not match glob patterns as names, select only exact name matches.\n"
" -p|--pool POOL Filter images by pool ID or name\n"
" -l|--long Also report allocated size and I/O statistics\n"
" --del Also include delete operation statistics\n"
@@ -275,7 +276,7 @@ static json11::Json::object parse_args(int narg, const char *args[])
!strcmp(opt, "allow-data-loss") || !strcmp(opt, "allow_data_loss") ||
!strcmp(opt, "down-ok") || !strcmp(opt, "down_ok") ||
!strcmp(opt, "dry-run") || !strcmp(opt, "dry_run") ||
!strcmp(opt, "help") || !strcmp(opt, "all") ||
!strcmp(opt, "help") || !strcmp(opt, "all") || !strcmp(opt, "exact") ||
!strcmp(opt, "writers-stopped") || !strcmp(opt, "writers_stopped"))
{
cfg[opt] = "1";
+4 -2
View File
@@ -18,6 +18,7 @@ struct image_lister_t
std::string sort_field;
std::set<std::string> only_names;
bool reverse = false;
bool exact = false;
int max_count = 0;
bool show_stats = false, show_delete = false;
@@ -208,9 +209,9 @@ resume_1:
}
else
{
for (auto glob: only_names)
for (auto & glob: only_names)
{
if (stupid_glob(kv.second["name"].string_value(), glob))
if (exact ? (kv.second["name"].string_value() == glob) : stupid_glob(kv.second["name"].string_value(), glob))
{
list.push_back(kv.second);
break;
@@ -538,6 +539,7 @@ std::function<bool(cli_result_t &)> cli_tool_t::start_ls(json11::Json cfg)
{
auto lister = new image_lister_t();
lister->parent = this;
lister->exact = cfg["exact"].bool_value();
lister->list_pool_id = cfg["pool"].uint64_value();
lister->list_pool_name = lister->list_pool_id ? "" : cfg["pool"].as_string();
lister->show_stats = cfg["long"].bool_value();