On 10/07/2010 04:27 PM, Denys Vlasenko wrote:
On Thu, 2010-10-07 at 13:27 +0200, Nikola Pajkovsky wrote:
> I have a few ideas how to make abrt-cli more powerful.
>
> First, transform abrt-cli --command to abrt-cli command.
What is the substance of this change? Less typing?
Easier to code this up? Something else?
Separation.
> Each command will be in separate file.
Do you mean "separate binary"?
Just separate module.
> Each command can take as your own ARGS.
I did not understand this part.
e.g. abrt-cli list --full --pretty=oneline
^^ ^^
arg arg
> $ abrt-cli
> usage abrt-cli [--help] COMMAND [ARGS]
>
> The most commonly used abrt-cli commands are:
> list Prints list of crashes which are not reported yet
> ...
> ...
> ...
> See 'abrt-cli COMMAND --help' for more information on a specific command
>
> What do you think?
A bit more info is needed...
Whole idea is separate and make code more flexible.
struct cmd_struct {
const char *cmd;
int (*fn)(int, char **);
const char *help;
};
List of all commands for abrt-cli(just example)
static struct cmd_struct commands[] = {
{ "list", cmd_list, "Prints list of crashes which are not reported
yet"},
};
it's snip from code
static void handle_internal_command(int argc, char **argv)
{
char *cmd = argv[0];
for (int i = 0; i < ARRAY_SIZE(commands); i++)
{
struct cmd_struct *p = commands + i;
if(strcmp(p->cmd, cmd))
continue;
// the idea is that we will have for each command separate module
// e.g. for list will be list.[c,cpp] see code below.
int status = p->fn(argc, argv);
}
}
static int full_opt, test_opt;
static struct options list_options[] = {
OPT_BOOL( 'f' , "full", &full_opt, "print a list of all
crashes, including the already reported ones"),
OPT_BOOL( 'h' , "help", &test_opt, "help"),
OPT_END()
};
int cmd_list(int argc, char **argv)
{
parse_opts(argc, argv, list_options, builtin_list_usage);
DBusError err;
dbus_error_init(&err);
s_dbus_conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);
handle_dbus_err(s_dbus_conn == NULL, &err);
vector_map_crash_data_t ci = call_GetCrashInfos();
print_crash_list(ci, full_opt);
return 0;
}
Pretty simple, readable and flexible.
--
Nikola