fx.cmdline: convert to new assembly build system

This commit is contained in:
2026-05-03 16:49:33 +01:00
parent 44fed67d43
commit f4469c9eb0
10 changed files with 591 additions and 279 deletions
+27 -12
View File
@@ -1,7 +1,7 @@
#include "command.h"
#include <fx/cmd.h>
#include <fx/ds/string.h>
#include <fx/string.h>
#include <stdlib.h>
#include <string.h>
@@ -58,7 +58,8 @@ const char *fx_command_option_get_description(struct fx_command_option *opt)
}
fx_status fx_command_option_set_long_name(
struct fx_command_option *opt, const char *name)
struct fx_command_option *opt,
const char *name)
{
char *n = fx_strdup(name);
if (!n) {
@@ -74,14 +75,17 @@ fx_status fx_command_option_set_long_name(
return FX_SUCCESS;
}
fx_status fx_command_option_set_short_name(struct fx_command_option *opt, char name)
fx_status fx_command_option_set_short_name(
struct fx_command_option *opt,
char name)
{
opt->opt_short_name = name;
return FX_SUCCESS;
}
fx_status fx_command_option_set_description(
struct fx_command_option *opt, const char *description)
struct fx_command_option *opt,
const char *description)
{
char *desc = fx_strdup(description);
if (!desc) {
@@ -97,7 +101,9 @@ fx_status fx_command_option_set_description(
return FX_SUCCESS;
}
struct fx_command_arg *fx_command_option_add_arg(struct fx_command_option *opt, int id)
struct fx_command_arg *fx_command_option_add_arg(
struct fx_command_option *opt,
int id)
{
struct fx_command_arg *arg = malloc(sizeof *arg);
if (!arg) {
@@ -139,7 +145,9 @@ void z__fx_get_option_description(struct fx_command_option *opt, fx_string *out)
if (nr_args > 1) {
fx_string_append_cstrf(
out, "values for `%s`:", arg->arg_name);
out,
"values for `%s`:",
arg->arg_name);
} else {
fx_string_append_cstr(out, "values:");
}
@@ -150,7 +158,8 @@ void z__fx_get_option_description(struct fx_command_option *opt, fx_string *out)
}
fx_string_append_cstrf(
out, " " F_GREEN "%s" F_RESET,
out,
" " F_GREEN "%s" F_RESET,
arg->arg_allowed_values[i]);
}
@@ -165,7 +174,9 @@ void z__fx_get_option_description(struct fx_command_option *opt, fx_string *out)
}
void z__fx_get_option_usage_string(
struct fx_command_option *opt, enum cmd_string_flags flags, fx_string *out)
struct fx_command_option *opt,
enum cmd_string_flags flags,
fx_string *out)
{
if (flags & CMD_STR_DIRECT_USAGE) {
fx_string_append_cstr(out, "{");
@@ -174,19 +185,22 @@ void z__fx_get_option_usage_string(
if (opt->opt_short_name) {
fx_string_append_cstrf(
out,
(flags & CMD_STR_COLOUR) ? F_GREEN "-%c" F_RESET : "-%c",
(flags & CMD_STR_COLOUR) ? F_GREEN "-%c" F_RESET
: "-%c",
opt->opt_short_name);
}
if (opt->opt_short_name && opt->opt_long_name) {
fx_string_append_cstr(
out, (flags & CMD_STR_DIRECT_USAGE) ? "|" : ", ");
out,
(flags & CMD_STR_DIRECT_USAGE) ? "|" : ", ");
}
if (opt->opt_long_name) {
fx_string_append_cstrf(
out,
(flags & CMD_STR_COLOUR) ? F_GREEN "--%s" F_RESET : "--%s",
(flags & CMD_STR_COLOUR) ? F_GREEN "--%s" F_RESET
: "--%s",
opt->opt_long_name);
}
@@ -254,7 +268,8 @@ void z__fx_get_option_usage_string(
}
struct fx_command_arg *fx_command_option_get_arg_with_id(
struct fx_command_option *opt, unsigned int id)
struct fx_command_option *opt,
unsigned int id)
{
struct fx_queue_entry *entry = fx_queue_first(&opt->opt_args);