verbs: use strv_find_closest()

This also makes the list of verbs is always shown on failure.
This commit is contained in:
Yu Watanabe
2024-09-21 05:10:47 +09:00
parent ffdf497860
commit 07919a1857
2 changed files with 43 additions and 74 deletions
+22
View File
@@ -54,6 +54,28 @@ TEST(verbs_no_default) {
};
test_dispatch_one(STRV_MAKE(NULL), verbs, -EINVAL);
test_dispatch_one(STRV_MAKE("hel"), verbs, -EINVAL);
test_dispatch_one(STRV_MAKE("helpp"), verbs, -EINVAL);
test_dispatch_one(STRV_MAKE("hgrejgoraoiosafso"), verbs, -EINVAL);
}
TEST(verbs_no_default_many) {
static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, noop_dispatcher },
{ "list-images", VERB_ANY, 1, 0, noop_dispatcher },
{ "list", VERB_ANY, 2, 0, noop_dispatcher },
{ "status", 2, VERB_ANY, 0, noop_dispatcher },
{ "show", VERB_ANY, VERB_ANY, 0, noop_dispatcher },
{ "terminate", 2, VERB_ANY, 0, noop_dispatcher },
{ "login", 2, 2, 0, noop_dispatcher },
{ "copy-to", 3, 4, 0, noop_dispatcher },
{}
};
test_dispatch_one(STRV_MAKE(NULL), verbs, -EINVAL);
test_dispatch_one(STRV_MAKE("hel"), verbs, -EINVAL);
test_dispatch_one(STRV_MAKE("helpp"), verbs, -EINVAL);
test_dispatch_one(STRV_MAKE("hgrejgoraoiosafso"), verbs, -EINVAL);
}
DEFINE_TEST_MAIN(LOG_INFO);