2026-05-25 10:33:29 +01:00
|
|
|
#include <bshell/command/cmdlet.h>
|
|
|
|
|
#include <bshell/command/command.h>
|
|
|
|
|
#include <bshell/runtime/pipeline.h>
|
|
|
|
|
#include <bshell/status.h>
|
2026-05-24 20:22:19 +01:00
|
|
|
#include <fx/reflection/function.h>
|
|
|
|
|
#include <fx/string.h>
|
|
|
|
|
#include <fx/vector.h>
|
|
|
|
|
|
|
|
|
|
#define BSHELL_TYPE_GET_VERB (bshell_get_verb_get_type())
|
|
|
|
|
|
|
|
|
|
fx_type_id bshell_get_verb_get_type(void);
|
|
|
|
|
|
|
|
|
|
FX_DECLARE_TYPE(bshell_get_verb);
|
|
|
|
|
|
|
|
|
|
FX_TYPE_CLASS_DECLARATION_BEGIN(bshell_get_verb)
|
|
|
|
|
FX_TYPE_CLASS_DECLARATION_END(bshell_get_verb)
|
|
|
|
|
|
|
|
|
|
struct bshell_get_verb_p {
|
|
|
|
|
fx_hashtable *c_verbs;
|
2026-05-25 19:14:45 +01:00
|
|
|
const fx_iterator *c_it;
|
2026-05-24 20:22:19 +01:00
|
|
|
};
|
|
|
|
|
|
2026-06-13 13:48:19 +01:00
|
|
|
static enum bshell_status begin_processing(
|
|
|
|
|
bshell_cmdlet *cmdlet,
|
|
|
|
|
enum bshell_command_position position)
|
2026-05-24 20:22:19 +01:00
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_get_verb_p *p
|
|
|
|
|
= fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB);
|
2026-05-24 20:22:19 +01:00
|
|
|
p->c_verbs = bshell_get_all_verbs();
|
|
|
|
|
p->c_it = fx_iterator_begin(p->c_verbs);
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum bshell_status process_record(
|
|
|
|
|
bshell_cmdlet *cmdlet,
|
|
|
|
|
bshell_pipeline *pipeline,
|
|
|
|
|
struct bshell_runtime *rt)
|
|
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_get_verb_p *p
|
|
|
|
|
= fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB);
|
2026-05-24 20:22:19 +01:00
|
|
|
|
|
|
|
|
do {
|
2026-05-25 19:14:45 +01:00
|
|
|
const fx_value *v = fx_iterator_get_value(p->c_it);
|
|
|
|
|
if (!v) {
|
2026-05-24 20:22:19 +01:00
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fx_hashtable_item *item = NULL;
|
2026-05-25 19:14:45 +01:00
|
|
|
fx_value_get_object(v, &item);
|
2026-05-24 20:22:19 +01:00
|
|
|
|
|
|
|
|
v = fx_hashtable_item_get_value(item);
|
|
|
|
|
|
|
|
|
|
bshell_verb *verb = NULL;
|
2026-05-25 19:14:45 +01:00
|
|
|
fx_value_get_object(v, &verb);
|
2026-05-24 20:22:19 +01:00
|
|
|
fx_iterator_move_next(p->c_it);
|
|
|
|
|
|
|
|
|
|
if (bshell_verb_is_reserved(verb)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-30 19:53:15 +01:00
|
|
|
bshell_pipeline_write_value(pipeline, *v, false);
|
2026-05-24 20:22:19 +01:00
|
|
|
break;
|
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static enum bshell_status end_processing(bshell_cmdlet *cmdlet)
|
|
|
|
|
{
|
2026-05-25 10:33:29 +01:00
|
|
|
struct bshell_get_verb_p *p
|
|
|
|
|
= fx_object_get_private(cmdlet, BSHELL_TYPE_GET_VERB);
|
2026-05-24 20:22:19 +01:00
|
|
|
if (p->c_it) {
|
|
|
|
|
fx_iterator_unref(p->c_it);
|
|
|
|
|
p->c_it = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BSHELL_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void init(fx_object *obj, void *priv)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FX_TYPE_CLASS_BEGIN(bshell_get_verb)
|
|
|
|
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(fx_object, FX_TYPE_OBJECT)
|
|
|
|
|
FX_INTERFACE_ENTRY(to_string) = NULL;
|
|
|
|
|
FX_TYPE_VTABLE_INTERFACE_END(fx_object, FX_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(bshell_cmdlet, BSHELL_TYPE_CMDLET)
|
|
|
|
|
FX_INTERFACE_ENTRY(c_verb) = BSHELL_VERB_GET;
|
|
|
|
|
FX_INTERFACE_ENTRY(c_noun) = "Verb";
|
|
|
|
|
FX_TYPE_VTABLE_INTERFACE_END(bshell_cmdlet, BSHELL_TYPE_CMDLET)
|
|
|
|
|
|
|
|
|
|
FX_TYPE_VTABLE_INTERFACE_BEGIN(bshell_command, BSHELL_TYPE_COMMAND)
|
|
|
|
|
FX_INTERFACE_ENTRY(c_begin_processing) = begin_processing;
|
|
|
|
|
FX_INTERFACE_ENTRY(c_process_record) = process_record;
|
|
|
|
|
FX_INTERFACE_ENTRY(c_end_processing) = end_processing;
|
|
|
|
|
FX_TYPE_VTABLE_INTERFACE_END(bshell_cmdlet, BSHELL_TYPE_CMDLET)
|
|
|
|
|
FX_TYPE_CLASS_END(bshell_get_verb)
|
|
|
|
|
|
|
|
|
|
FX_TYPE_DEFINITION_BEGIN(bshell_get_verb)
|
|
|
|
|
FX_TYPE_ID(0xa47976a6, 0xf7d8, 0x447f, 0x887b, 0x6c5d78b7bd2e);
|
|
|
|
|
FX_TYPE_NAME("bshell.core.get_verb");
|
|
|
|
|
FX_TYPE_EXTENDS(BSHELL_TYPE_CMDLET);
|
|
|
|
|
FX_TYPE_CLASS(bshell_get_verb_class);
|
|
|
|
|
FX_TYPE_INSTANCE_INIT(init);
|
|
|
|
|
FX_TYPE_INSTANCE_PRIVATE(struct bshell_get_verb_p);
|
|
|
|
|
FX_TYPE_DEFINITION_END(bshell_get_verb)
|