61 lines
1.5 KiB
C
61 lines
1.5 KiB
C
|
|
#include "cmdlet.h"
|
||
|
|
|
||
|
|
#include "../status.h"
|
||
|
|
#include "command.h"
|
||
|
|
|
||
|
|
#include <fx/reflection/function.h>
|
||
|
|
#include <fx/string.h>
|
||
|
|
#include <fx/vector.h>
|
||
|
|
|
||
|
|
struct bshell_cmdlet_p {
|
||
|
|
};
|
||
|
|
|
||
|
|
static void init(fx_object *obj, void *priv)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
static enum bshell_status get_callable_name_static(
|
||
|
|
const fx_type *ty,
|
||
|
|
fx_string *out)
|
||
|
|
{
|
||
|
|
bshell_cmdlet_class *class = fx_type_get_interface(
|
||
|
|
ty,
|
||
|
|
BSHELL_TYPE_CMDLET);
|
||
|
|
if (!class) {
|
||
|
|
return BSHELL_ERR_NOT_SUPPORTED;
|
||
|
|
}
|
||
|
|
|
||
|
|
const bshell_verb *verb_info = bshell_verb_get_by_id(class->c_verb);
|
||
|
|
if (!verb_info) {
|
||
|
|
return BSHELL_ERR_BAD_STATE;
|
||
|
|
}
|
||
|
|
|
||
|
|
fx_string_append_cstrf(
|
||
|
|
out,
|
||
|
|
"%s-%s",
|
||
|
|
bshell_verb_get_name(verb_info),
|
||
|
|
class->c_noun);
|
||
|
|
return BSHELL_SUCCESS;
|
||
|
|
}
|
||
|
|
|
||
|
|
FX_TYPE_CLASS_BEGIN(bshell_cmdlet)
|
||
|
|
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_command, BSHELL_TYPE_COMMAND)
|
||
|
|
FX_INTERFACE_ENTRY(c_command_type) = "Cmdlet";
|
||
|
|
FX_INTERFACE_ENTRY(c_get_callable_name_static)
|
||
|
|
= get_callable_name_static;
|
||
|
|
FX_TYPE_VTABLE_INTERFACE_END(bshell_command, BSHELL_TYPE_COMMAND)
|
||
|
|
FX_TYPE_CLASS_END(bshell_cmdlet)
|
||
|
|
|
||
|
|
FX_TYPE_DEFINITION_BEGIN(bshell_cmdlet)
|
||
|
|
FX_TYPE_ID(0xc71f4d59, 0x8066, 0x4294, 0xa6b0, 0xe1f3eb04f454);
|
||
|
|
FX_TYPE_NAME("bshell.cmdlet");
|
||
|
|
FX_TYPE_EXTENDS(BSHELL_TYPE_COMMAND);
|
||
|
|
FX_TYPE_CLASS(bshell_cmdlet_class);
|
||
|
|
FX_TYPE_INSTANCE_INIT(init);
|
||
|
|
FX_TYPE_INSTANCE_PRIVATE(struct bshell_cmdlet_p);
|
||
|
|
FX_TYPE_DEFINITION_END(bshell_cmdlet)
|