fx.cmdline: convert to new assembly build system
This commit is contained in:
+59
-28
@@ -1,13 +1,14 @@
|
||||
#include "command.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <fx/core/stringstream.h>
|
||||
#include <fx/ds/string.h>
|
||||
#include <fx/string.h>
|
||||
#include <fx/stringstream.h>
|
||||
#include <fx/term/print.h>
|
||||
#include <stdio.h>
|
||||
|
||||
enum fx_status fx_arglist_report_missing_option(
|
||||
const fx_arglist *args, unsigned int opt_id)
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id)
|
||||
{
|
||||
struct fx_command_option *opt = NULL;
|
||||
|
||||
@@ -35,7 +36,10 @@ enum fx_status fx_arglist_report_missing_option(
|
||||
|
||||
if (opt_names == 2) {
|
||||
fx_stream_write_fmt(
|
||||
opt_name, NULL, "-%c / --%s", opt->opt_short_name,
|
||||
opt_name,
|
||||
NULL,
|
||||
"-%c / --%s",
|
||||
opt->opt_short_name,
|
||||
opt->opt_long_name);
|
||||
} else if (opt->opt_short_name) {
|
||||
fx_stream_write_fmt(opt_name, NULL, "-%c", opt->opt_short_name);
|
||||
@@ -44,7 +48,7 @@ enum fx_status fx_arglist_report_missing_option(
|
||||
}
|
||||
|
||||
fx_err("required option `" F_YELLOW "%s" F_RESET "` was not specified.",
|
||||
fx_stringstream_ptr(opt_name));
|
||||
fx_stringstream_ptr(opt_name));
|
||||
fx_i("usage: %s", fx_string_get_cstr(opt_string));
|
||||
fx_i("for more information, use `" F_YELLOW "--help" F_RESET "`");
|
||||
|
||||
@@ -55,10 +59,13 @@ enum fx_status fx_arglist_report_missing_option(
|
||||
}
|
||||
|
||||
enum fx_status fx_arglist_report_unexpected_arg(
|
||||
const fx_arglist *args, const char *value)
|
||||
const fx_arglist *args,
|
||||
const char *value)
|
||||
{
|
||||
fx_string *usage = z__fx_command_default_usage_string(
|
||||
args->list_command, NULL, args);
|
||||
args->list_command,
|
||||
NULL,
|
||||
args);
|
||||
|
||||
fx_err("unexpected argument '" F_YELLOW "%s" F_RESET "' found.", value);
|
||||
fx_i("usage: %s", fx_string_get_cstr(usage));
|
||||
@@ -68,7 +75,9 @@ enum fx_status fx_arglist_report_unexpected_arg(
|
||||
}
|
||||
|
||||
enum fx_status fx_arglist_report_invalid_arg_value(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id,
|
||||
const char *value)
|
||||
{
|
||||
struct fx_command_option *opt = NULL;
|
||||
@@ -80,11 +89,15 @@ enum fx_status fx_arglist_report_invalid_arg_value(
|
||||
|
||||
if (arg_id != FX_COMMAND_INVALID_ID) {
|
||||
arg = opt ? fx_command_option_get_arg_with_id(opt, arg_id)
|
||||
: fx_command_get_arg_with_id(args->list_command, arg_id);
|
||||
: fx_command_get_arg_with_id(
|
||||
args->list_command,
|
||||
arg_id);
|
||||
}
|
||||
|
||||
fx_string *usage = z__fx_command_default_usage_string(
|
||||
args->list_command, opt, args);
|
||||
args->list_command,
|
||||
opt,
|
||||
args);
|
||||
fx_string *opt_string = fx_string_create();
|
||||
|
||||
if (opt) {
|
||||
@@ -94,17 +107,20 @@ enum fx_status fx_arglist_report_invalid_arg_value(
|
||||
}
|
||||
|
||||
fx_err("invalid value '" F_YELLOW "%s" F_RESET "' for '" F_YELLOW
|
||||
"%s" F_RESET "'.",
|
||||
value, fx_string_get_cstr(opt_string));
|
||||
"%s" F_RESET "'.",
|
||||
value,
|
||||
fx_string_get_cstr(opt_string));
|
||||
|
||||
if (opt) {
|
||||
fx_i("'" F_YELLOW "%s" F_RESET
|
||||
"' accepts the following values for '" F_YELLOW "%s" F_RESET
|
||||
"':",
|
||||
fx_string_get_cstr(opt_string), arg->arg_name);
|
||||
"' accepts the following values for '" F_YELLOW
|
||||
"%s" F_RESET "':",
|
||||
fx_string_get_cstr(opt_string),
|
||||
arg->arg_name);
|
||||
} else {
|
||||
fx_i("'" F_YELLOW "%s" F_RESET "' accepts the following values:",
|
||||
fx_string_get_cstr(opt_string));
|
||||
fx_i("'" F_YELLOW "%s" F_RESET
|
||||
"' accepts the following values:",
|
||||
fx_string_get_cstr(opt_string));
|
||||
}
|
||||
|
||||
for (int i = 0; arg->arg_allowed_values[i]; i++) {
|
||||
@@ -124,7 +140,9 @@ enum fx_status fx_arglist_report_invalid_arg_value(
|
||||
}
|
||||
|
||||
enum fx_status fx_arglist_report_missing_args(
|
||||
const fx_arglist *args, unsigned int opt_id, unsigned int arg_id,
|
||||
const fx_arglist *args,
|
||||
unsigned int opt_id,
|
||||
unsigned int arg_id,
|
||||
size_t args_supplied)
|
||||
{
|
||||
struct fx_command_option *opt = NULL;
|
||||
@@ -137,12 +155,16 @@ enum fx_status fx_arglist_report_missing_args(
|
||||
|
||||
if (arg_id != FX_COMMAND_INVALID_ID) {
|
||||
arg = opt ? fx_command_option_get_arg_with_id(opt, arg_id)
|
||||
: fx_command_get_arg_with_id(args->list_command, arg_id);
|
||||
: fx_command_get_arg_with_id(
|
||||
args->list_command,
|
||||
arg_id);
|
||||
assert(arg);
|
||||
}
|
||||
|
||||
fx_string *usage = z__fx_command_default_usage_string(
|
||||
args->list_command, opt, args);
|
||||
args->list_command,
|
||||
opt,
|
||||
args);
|
||||
fx_string *opt_string = fx_string_create();
|
||||
|
||||
if (opt) {
|
||||
@@ -154,16 +176,19 @@ enum fx_status fx_arglist_report_missing_args(
|
||||
char supplied_arg_str[64];
|
||||
if (args_supplied == 0) {
|
||||
snprintf(
|
||||
supplied_arg_str, sizeof supplied_arg_str,
|
||||
supplied_arg_str,
|
||||
sizeof supplied_arg_str,
|
||||
F_RED_BOLD "none" F_RESET " were provided");
|
||||
} else if (args_supplied == 1) {
|
||||
snprintf(
|
||||
supplied_arg_str, sizeof supplied_arg_str,
|
||||
supplied_arg_str,
|
||||
sizeof supplied_arg_str,
|
||||
"only " F_YELLOW_BOLD "%zu" F_RESET " was provided",
|
||||
args_supplied);
|
||||
} else {
|
||||
snprintf(
|
||||
supplied_arg_str, sizeof supplied_arg_str,
|
||||
supplied_arg_str,
|
||||
sizeof supplied_arg_str,
|
||||
"only " F_YELLOW_BOLD "%zu" F_RESET " were provided",
|
||||
args_supplied);
|
||||
}
|
||||
@@ -172,19 +197,25 @@ enum fx_status fx_arglist_report_missing_args(
|
||||
switch (arg->arg_nr_values) {
|
||||
case FX_ARG_1_OR_MORE_VALUES:
|
||||
snprintf(
|
||||
required_arg_count, sizeof required_arg_count,
|
||||
required_arg_count,
|
||||
sizeof required_arg_count,
|
||||
"one or more");
|
||||
break;
|
||||
default:
|
||||
snprintf(
|
||||
required_arg_count, sizeof required_arg_count, "%d",
|
||||
required_arg_count,
|
||||
sizeof required_arg_count,
|
||||
"%d",
|
||||
arg->arg_nr_values);
|
||||
}
|
||||
|
||||
fx_err("argument `" F_YELLOW "%s" F_RESET "` requires " F_GREEN_BOLD
|
||||
"%s" F_RESET " `" F_YELLOW "%s" F_RESET "` value%s, but %s.",
|
||||
fx_string_get_cstr(opt_string), required_arg_count, arg->arg_name,
|
||||
(arg->arg_nr_values == 1) ? "" : "s", supplied_arg_str);
|
||||
"%s" F_RESET " `" F_YELLOW "%s" F_RESET "` value%s, but %s.",
|
||||
fx_string_get_cstr(opt_string),
|
||||
required_arg_count,
|
||||
arg->arg_name,
|
||||
(arg->arg_nr_values == 1) ? "" : "s",
|
||||
supplied_arg_str);
|
||||
fx_i("usage: %s", fx_string_get_cstr(usage));
|
||||
fx_i("for more information, use '" F_YELLOW "--help" F_RESET "'");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user