Files
bluelib/cmd/command.h

142 lines
3.5 KiB
C
Raw Normal View History

2024-10-24 21:32:28 +01:00
#ifndef _B_COMMAND_H_
#define _B_COMMAND_H_
#include <blue/cmd.h>
#include <blue/core/btree.h>
#include <blue/core/queue.h>
#define F_RED "[bright,red]"
#define F_GREEN "[bright,green]"
#define F_YELLOW "[bright,yellow]"
2024-10-24 21:32:28 +01:00
#define F_RED_BOLD "[bright,bold,red]"
#define F_GREEN_BOLD "[bright,bold,green]"
#define F_YELLOW_BOLD "[bright,bold,yellow]"
#define F_RESET "[reset]"
2024-10-24 21:32:28 +01:00
enum cmd_string_flags {
CMD_STR_COLOUR = 0x01u,
CMD_STR_DIRECT_USAGE = 0x02u,
};
struct b_string;
struct b_command {
unsigned int b_id;
unsigned int b_parent_id;
struct b_command *b_parent;
enum b_command_flags b_flags;
char *b_name;
char *b_long_name;
char b_short_name;
char *b_description;
struct b_queue b_opt;
struct b_queue b_arg;
struct b_queue b_subcommands;
struct b_queue b_usage;
b_command_callback b_callback;
struct b_queue_entry b_entry;
struct b_btree_node b_node;
};
struct b_command_usage_opt {
struct b_queue_entry opt_entry;
struct b_command_option *opt;
};
struct b_command_usage_arg {
struct b_queue_entry arg_entry;
struct b_command_arg *arg;
};
struct b_command_usage_command {
struct b_queue_entry cmd_entry;
unsigned int cmd_id;
};
2024-10-24 21:32:28 +01:00
struct b_command_usage {
b_command_usage_flags u_flags;
struct b_queue_entry u_entry;
struct b_queue u_cmd;
2024-10-24 21:32:28 +01:00
struct b_queue u_opt;
struct b_queue u_arg;
};
struct b_command_option {
unsigned int opt_id;
char *opt_long_name;
char opt_short_name;
char *opt_description;
// b_command_arg_value_count arg_nr_values;
// char **arg_allowed_values;
struct b_queue opt_args;
struct b_queue_entry opt_entry;
};
struct b_command_arg {
unsigned int arg_id;
char *arg_name;
char *arg_description;
b_command_arg_value_count arg_nr_values;
char **arg_allowed_values;
struct b_queue_entry arg_entry;
};
2024-10-27 19:43:05 +00:00
struct b_arglist_option {
unsigned int opt_id;
struct b_btree opt_values;
struct b_btree_node opt_node;
};
struct b_arglist {
struct b_btree list_options;
};
2024-11-14 16:56:12 +00:00
BLUE_API struct b_command *b_command_get_subcommand_with_name(
2024-10-24 21:32:28 +01:00
struct b_command *cmd, const char *name);
2024-11-14 16:56:12 +00:00
BLUE_API struct b_command *b_command_get_subcommand_with_long_name(
2024-10-24 21:32:28 +01:00
struct b_command *cmd, const char *long_name);
2024-11-14 16:56:12 +00:00
BLUE_API struct b_command *b_command_get_subcommand_with_short_name(
2024-10-24 21:32:28 +01:00
struct b_command *cmd, char short_name);
2024-11-14 16:56:12 +00:00
BLUE_API struct b_command_option *b_command_get_option_with_long_name(
2024-10-24 21:32:28 +01:00
struct b_command *cmd, const char *long_name);
2024-11-14 16:56:12 +00:00
BLUE_API struct b_command_option *b_command_get_option_with_short_name(
2024-10-24 21:32:28 +01:00
struct b_command *cmd, char short_name);
2024-11-14 16:56:12 +00:00
BLUE_API struct b_command_option *b_command_option_create(void);
BLUE_API void b_command_option_destroy(struct b_command_option *opt);
2024-10-27 19:43:05 +00:00
2024-11-14 16:56:12 +00:00
BLUE_API struct b_command_arg *b_command_arg_create(void);
BLUE_API void b_command_arg_destroy(struct b_command_arg *arg);
2024-10-27 19:43:05 +00:00
2024-11-14 16:56:12 +00:00
BLUE_API struct b_arglist *b_arglist_create(void);
BLUE_API b_status b_arglist_parse(
2024-10-24 21:32:28 +01:00
struct b_arglist *args, struct b_command **cmd, int argc,
const char **argv);
2024-11-14 16:56:12 +00:00
BLUE_API void b_arglist_destroy(struct b_arglist *args);
2024-10-24 21:32:28 +01:00
2024-11-14 16:56:12 +00:00
BLUE_API struct b_string *z__b_command_default_usage_string(
2024-10-24 21:32:28 +01:00
struct b_command *cmd, struct b_command_option *with_opt);
2024-11-14 16:56:12 +00:00
BLUE_API void z__b_get_arg_usage_string(
2024-10-24 21:32:28 +01:00
struct b_command_arg *arg, bool colour, struct b_string *out);
2024-11-14 16:56:12 +00:00
BLUE_API void z__b_get_arg_description(
2024-10-24 21:32:28 +01:00
struct b_command_arg *arg, struct b_string *out);
2024-11-14 16:56:12 +00:00
BLUE_API void z__b_get_option_usage_string(
2024-10-24 21:32:28 +01:00
struct b_command_option *opt, enum cmd_string_flags flags,
struct b_string *out);
2024-11-14 16:56:12 +00:00
BLUE_API void z__b_get_option_description(
2024-10-24 21:32:28 +01:00
struct b_command_option *opt, struct b_string *out);
#endif