[cli] Extend command function signature to take a command info.
authorMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 16 Apr 2009 18:30:16 +0000 (20:30 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 16 Apr 2009 18:30:16 +0000 (20:30 +0200)
Signed-off-by: Matthias Bolte <matthias.bolte@googlemail.com>

cli/core.c
cli/help.c
include/libvsccli/types.h

index eeae6fd..1961242 100644 (file)
@@ -45,8 +45,8 @@ int _vsc_cli_output_coloring = TRUE;
 int _vsc_cli_interactive = FALSE;
 
 static void
-_quit (struct VscError *error, const struct VscCliOption *option_list,
-       void *user_data);
+_quit (struct VscError *error, const struct VscCliCommandInfo *command_info,
+       const struct VscCliOption *option_list, void *user_data);
 
 static const struct VscCliOptionInfo _quit_option_infos[] = {
        { -1, NULL, NULL, 0, FALSE },
@@ -62,6 +62,7 @@ const struct VscCliCommandInfo vsc_cli_quit_command_info = {
 
 static void
 _quit (struct VscError *error VSC__ATTR__UNUSED,
+       const struct VscCliCommandInfo *command_info VSC__ATTR__UNUSED,
        const struct VscCliOption *option_list VSC__ATTR__UNUSED,
        void *user_data VSC__ATTR__UNUSED)
 {
@@ -378,7 +379,8 @@ vsc_cli_run_command_list (struct VscError *error,
 
        for (command = (struct VscCliCommand *) command_list; command != NULL;
             command = command->next) {
-               command->info->function (error, command->option_list, user_data);
+               command->info->function (error, command->info, command->option_list,
+                                        user_data);
 
                if (error->occured) {
                        VSC__APPEND_ERROR0 (error, VSC__ERROR_CODE__TRACE);
index a45ab2e..db9465b 100644 (file)
@@ -36,8 +36,8 @@ extern int _vsc_cli_output_coloring;
 extern int _vsc_cli_interactive;
 
 static void
-_help (struct VscError *error, const struct VscCliOption *option_list,
-       void *user_data);
+_help (struct VscError *error, const struct VscCliCommandInfo *command_info,
+       const struct VscCliOption *option_list, void *user_data);
 
 static const struct VscCliOptionInfo _help_option_infos[] = {
        { -1, "command", "name of command", VSC_CLI__OPTION_TYPE__DATA, FALSE },
@@ -53,12 +53,14 @@ const struct VscCliCommandInfo vsc_cli_help_command_info = {
 };
 
 static void
-_help (struct VscError *error, const struct VscCliOption *option_list,
+_help (struct VscError *error,
+       const struct VscCliCommandInfo *command_info VSC__ATTR__UNUSED,
+       const struct VscCliOption *option_list,
        void *user_data VSC__ATTR__UNUSED)
 {
        int i;
        const char *command_name;
-       const struct VscCliCommandInfo *command_info;
+       const struct VscCliCommandInfo *command_info_;
        const struct VscCliOptionInfo *option_info;
 
        VSC__ASSERT (error != NULL);
@@ -67,23 +69,25 @@ _help (struct VscError *error, const struct VscCliOption *option_list,
        command_name = vsc_cli_option_get_string (option_list, "command");
 
        if (command_name != NULL) {
-               command_info = _vsc_cli_command_info_lookup (command_name);
+               command_info_ = _vsc_cli_command_info_lookup (command_name);
 
-               if (command_info == NULL) {
+               if (command_info_ == NULL) {
                        VSC__ERROR2 (error, VSC__ERROR_CODE__INTERNAL_ERROR,
                                     "help: Command '%s' is unknown", command_name);
                        return;
                }
 
-               printf (_vsc_cli_output_coloring ? "\033[1mNAME\033[0m\n" : "NAME\n");
-               printf ("       %s - %s\n", command_info->name, command_info->help);
+               printf (_vsc_cli_output_coloring ? "\033[1mNAME\033[0m\n"
+                                                : "NAME\n");
+               printf ("       %s - %s\n", command_info_->name, command_info_->help);
                printf ("\n");
 
-               printf (_vsc_cli_output_coloring ? "\033[1mSYNOPSIS\033[0m\n" : "SYNOPSIS\n");
-               printf ("       %s", command_info->name);
+               printf (_vsc_cli_output_coloring ? "\033[1mSYNOPSIS\033[0m\n"
+                                                : "SYNOPSIS\n");
+               printf ("       %s", command_info_->name);
 
-               for (i = 0; command_info->option_infos[i].long_name != NULL; ++i) {
-                       option_info = &command_info->option_infos[i];
+               for (i = 0; command_info_->option_infos[i].long_name != NULL; ++i) {
+                       option_info = &command_info_->option_infos[i];
 
                        if (option_info->required) {
                                printf (" %s", _vsc_cli_option_syntax (option_info, TRUE));
@@ -94,28 +98,28 @@ _help (struct VscError *error, const struct VscCliOption *option_list,
 
                printf ("\n");
 
-               if (command_info->description != NULL &&
-                   *command_info->description != '\0') {
+               if (command_info_->description != NULL &&
+                   *command_info_->description != '\0') {
                        printf ("\n");
                        printf (_vsc_cli_output_coloring ? "\033[1mDESCRIPTION\033[0m\n"
                                                         : "DESCRIPTION\n");
-                       printf ("       %s\n", command_info->description);
+                       printf ("       %s\n", command_info_->description);
                }
 
-               if (command_info->option_infos[0].long_name != NULL) {
+               if (command_info_->option_infos[0].long_name != NULL) {
                        printf ("\n");
                        printf (_vsc_cli_output_coloring ? "\033[1mOPTIONS\033[0m\n"
                                                         : "OPTIONS\n");
 
-                       for (i = 0; command_info->option_infos[i].long_name != NULL; ++i) {
-                               option_info = &command_info->option_infos[i];
+                       for (i = 0; command_info_->option_infos[i].long_name != NULL; ++i) {
+                               option_info = &command_info_->option_infos[i];
 
                                printf ("       %s\n"
                                        "              %s\n",
                                        _vsc_cli_option_syntax (option_info, FALSE),
                                        option_info->help);
 
-                               if (command_info->option_infos[i + 1].long_name != NULL) {
+                               if (command_info_->option_infos[i + 1].long_name != NULL) {
                                        printf ("\n");
                                }
                        }
index 7fa7837..fa4d776 100644 (file)
@@ -35,9 +35,10 @@ enum VscCliOptionType {
 };
 
 struct VscCliOption;
-struct VscCliCommand;
+struct VscCliCommandInfo;
 
 typedef void (*VscCliCommandFunction) (struct VscError *error,
+                                       const struct VscCliCommandInfo *command_info,
                                        const struct VscCliOption *option_list,
                                        void *user_data);