Files
wash edfb3e24a3 bshell: re-organise build into three separate components
bshell: the front-end binary
bshell.runtime: contains the parser, compiler, and classes needed to run bshell scripts
bshell.core: contains the builtin commandlets and aliases
2026-05-25 10:33:29 +01:00

135 lines
3.3 KiB
C

#include <bshell/command/alias.h>
#include <bshell/command/command.h>
#include <bshell/status.h>
#include <fx/reflection/function.h>
#include <fx/string.h>
#include <fx/vector.h>
struct bshell_alias_p {
};
static void init(fx_object *obj, void *priv)
{
}
enum bshell_status bshell_alias_get_callable_name(
const bshell_alias *alias,
fx_string *out)
{
bshell_alias_class *c
= fx_object_get_interface(alias, BSHELL_TYPE_ALIAS);
if (!c) {
return BSHELL_ERR_NOT_SUPPORTED;
}
const char *callable_name = c->a_callable_name;
if (c->a_get_callable_name) {
callable_name = c->a_get_callable_name(alias);
}
if (callable_name) {
fx_string_append_cstr(out, callable_name);
}
return BSHELL_SUCCESS;
}
enum bshell_status bshell_alias_get_target_name(
const bshell_alias *alias,
fx_string *out)
{
bshell_alias_class *c
= fx_object_get_interface(alias, BSHELL_TYPE_ALIAS);
if (!c) {
return BSHELL_ERR_NOT_SUPPORTED;
}
const char *target_name = c->a_target_name;
if (c->a_get_target_name) {
target_name = c->a_get_target_name(alias);
}
if (target_name) {
fx_string_append_cstr(out, target_name);
}
return BSHELL_SUCCESS;
}
static enum bshell_status get_callable_name_static(
const fx_type *ty,
fx_string *out)
{
bshell_alias_class *c = fx_type_get_interface(ty, BSHELL_TYPE_ALIAS);
if (!c) {
return BSHELL_ERR_NOT_SUPPORTED;
}
if (c->a_callable_name) {
fx_string_append_cstr(out, c->a_callable_name);
}
return BSHELL_SUCCESS;
}
static enum bshell_status get_description(
const bshell_command *cmd,
fx_string *out)
{
bshell_alias_class *c = fx_object_get_interface(cmd, BSHELL_TYPE_ALIAS);
if (!c) {
return BSHELL_ERR_NOT_SUPPORTED;
}
const char *callable_name = c->a_callable_name;
if (c->a_get_callable_name) {
callable_name = c->a_get_callable_name(cmd);
}
const char *target_name = c->a_target_name;
if (c->a_get_target_name) {
target_name = c->a_get_target_name(cmd);
}
if (!callable_name || !target_name) {
return BSHELL_ERR_NOT_SUPPORTED;
}
fx_string_append_cstr(out, callable_name);
fx_string_append_cstr(out, " -> ");
fx_string_append_cstr(out, target_name);
return BSHELL_SUCCESS;
}
enum bshell_status get_description_static(const fx_type *ty, fx_string *out)
{
return BSHELL_SUCCESS;
}
FX_TYPE_CLASS_BEGIN(bshell_alias)
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) = "Alias";
FX_INTERFACE_ENTRY(c_get_callable_name)
= bshell_alias_get_callable_name;
FX_INTERFACE_ENTRY(c_get_callable_name_static)
= get_callable_name_static;
FX_INTERFACE_ENTRY(c_get_description) = get_description;
FX_INTERFACE_ENTRY(c_get_description_static)
= get_description_static;
FX_TYPE_VTABLE_INTERFACE_END(bshell_command, BSHELL_TYPE_COMMAND)
FX_TYPE_CLASS_END(bshell_alias)
FX_TYPE_DEFINITION_BEGIN(bshell_alias)
FX_TYPE_ID(0x1736c10e, 0xebe6, 0x4ba5, 0x83d9, 0x5da3b7dc706c);
FX_TYPE_FLAGS(FX_TYPE_F_ABSTRACT);
FX_TYPE_NAME("bshell.runtime.alias");
FX_TYPE_EXTENDS(BSHELL_TYPE_COMMAND);
FX_TYPE_CLASS(bshell_alias_class);
FX_TYPE_INSTANCE_INIT(init);
FX_TYPE_INSTANCE_PRIVATE(struct bshell_alias_p);
FX_TYPE_DEFINITION_END(bshell_alias)