[cli] Combine the tagged and required fields of the option info struct.
authorMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 21 Apr 2009 14:05:06 +0000 (16:05 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 21 Apr 2009 14:08:26 +0000 (16:08 +0200)
Signed-off-by: Matthias Bolte <matthias.bolte@googlemail.com>

cli/command.c
cli/core.c
cli/help.c
cli/option.c
include/libvsccli/option.h
include/libvsccli/types.h
remote/remote.c

index 6f23df5..0bcf284 100644 (file)
@@ -199,7 +199,7 @@ vsc_cli_command_parse (struct VscError *error,
                }
 
                if (option_parsed) {
-                       if (! option.info->tagged) {
+                       if (! (option.info->flags & VSC_CLI__OPTION_FLAG__TAGGED)) {
                                ++untagged_option_index;
                        }
 
@@ -222,7 +222,7 @@ vsc_cli_command_parse (struct VscError *error,
        for (i = 0; command_info->option_infos[i].long_name != NULL; ++i) {
                option_info = &command_info->option_infos[i];
 
-               if (! option_info->required) {
+               if (! (option_info->flags & VSC_CLI__OPTION_FLAG__REQUIRED)) {
                        continue;
                }
 
index ec4acbe..ac808a6 100644 (file)
@@ -95,7 +95,7 @@ _readline_command_generator (const char *text, int state)
 }
 
 static char *
-_readline_options_generator(const char *text, int state)
+_readline_options_generator (const char *text, int state)
 {
        static int last_index, text_length;
        static const struct VscCliCommandInfo *command_info = NULL;
@@ -149,7 +149,7 @@ _readline_options_generator(const char *text, int state)
                        option_info = &command_info->option_infos[last_index];
                        ++last_index;
 
-                       if (! option_info->tagged) {
+                       if (! (option_info->flags & VSC_CLI__OPTION_FLAG__TAGGED)) {
                                continue;
                        }
 
@@ -221,7 +221,7 @@ vsc_cli_init (struct VscError *error, const char *name, const char *help,
                        option_info = &command_info->option_infos[k];
 
                        if (option_info->type == VSC_CLI__OPTION_TYPE__BOOLEAN &&
-                               ! option_info->tagged) {
+                               ! (option_info->flags & VSC_CLI__OPTION_FLAG__TAGGED)) {
                                VSC__ERROR1 (error, VSC__ERROR_CODE__INVALID_ARGUMENT,
                                             "Boolean options can not untagged");
                                return;
@@ -330,7 +330,7 @@ vsc_cli_error_fprint (struct VscError *error, FILE *stream)
                } else {
                        fprintf (stream, "%s: %s\n",
                                 _vsc_cli_output_coloring ? prefix_colored : prefix,
-                                vsc_error_string(error->code));
+                                vsc_error_string (error->code));
                }
        }
 }
index 3de6a51..6e6cc75 100644 (file)
@@ -129,7 +129,7 @@ _help (struct VscError *error, const struct VscCliCommandInfo *command_info,
 
 static const struct VscCliOptionInfo _help_option_infos[] = {
        { -1, "command", "Name of command", VSC_CLI__OPTION_TYPE__STRING,
-         FALSE, FALSE },
+         VSC_CLI__OPTION_FLAG__NONE },
        VSC_CLI__NULL__OPTION_INFO,
 };
 
@@ -214,7 +214,7 @@ _help (struct VscError *error,
                        option_info = &command_info_->option_infos[i];
                        syntax = _vsc_cli_option_syntax (option_info, TRUE);
 
-                       if (option_info->required) {
+                       if (option_info->flags & VSC_CLI__OPTION_FLAG__REQUIRED) {
                                total = _limited_printf (indent, total, " %s", syntax);
                        } else {
                                total = _limited_printf (indent, total, " [%s]", syntax);
@@ -300,7 +300,7 @@ _help (struct VscError *error,
                                option_info = &_vsc_cli_option_infos[i];
                                syntax = _vsc_cli_option_syntax (option_info, TRUE);
 
-                               if (option_info->required) {
+                               if (option_info->flags & VSC_CLI__OPTION_FLAG__REQUIRED) {
                                        total = _limited_printf ("      ", total, " %s", syntax);
                                } else {
                                        total = _limited_printf ("      ", total, " [%s]", syntax);
index 8fb8de5..3ec6512 100644 (file)
@@ -39,7 +39,7 @@ _vsc_cli_option_syntax (const struct VscCliOptionInfo *option_info,
 
        VSC__ASSERT (option_info != NULL);
 
-       if (option_info->tagged) {
+       if (option_info->flags & VSC_CLI__OPTION_FLAG__TAGGED) {
                if (option_info->type == VSC_CLI__OPTION_TYPE__BOOLEAN) {
                        if (synopsis) {
                                snprintf (syntax, 512, "--%s", option_info->long_name);
@@ -340,7 +340,7 @@ _vsc_cli_option_infos_lookup_tagged
        VSC__ASSERT (option_name != NULL);
 
        for (i = 0; option_infos[i].long_name != NULL; i++) {
-               if (! option_infos[i].tagged) {
+               if (! (option_infos[i].flags & VSC_CLI__OPTION_FLAG__TAGGED)) {
                        continue;
                }
 
@@ -368,7 +368,7 @@ _vsc_cli_option_infos_lookup_untagged
        VSC__ASSERT (position >= 0);
 
        for (i = 0; option_infos[i].long_name != NULL; i++) {
-               if (! option_infos[i].tagged) {
+               if (! (option_infos[i].flags & VSC_CLI__OPTION_FLAG__TAGGED)) {
                        if (position > 0) {
                                --position;
                        } else {
index 1d996f4..45e9c5e 100644 (file)
 
 #include "types.h"
 
-#define VSC_CLI__NULL__OPTION_INFO { -1, NULL, NULL, 0, FALSE, FALSE }
+#define VSC_CLI__NULL__OPTION_INFO \
+       { -1, NULL, NULL, VSC_CLI__OPTION_TYPE__UNDEFINED, \
+         VSC_CLI__OPTION_FLAG__NONE }
 
 #define VSC_CLI__VERBOSE_ERRORS__OPTION_INFO__LONG_NAME "verbose-errors"
 #define VSC_CLI__VERBOSE_ERRORS__OPTION_INFO \
        { -1, VSC_CLI__VERBOSE_ERRORS__OPTION_INFO__LONG_NAME, \
          "Enable verbose error reporting", \
-         VSC_CLI__OPTION_TYPE__BOOLEAN, TRUE, FALSE }
+         VSC_CLI__OPTION_TYPE__BOOLEAN, VSC_CLI__OPTION_FLAG__TAGGED }
 
 #define VSC_CLI__NO_COLOR__OPTION_INFO__LONG_NAME "no-color"
 #define VSC_CLI__NO_COLOR__OPTION_INFO \
        { -1, VSC_CLI__NO_COLOR__OPTION_INFO__LONG_NAME, \
          "Disable output coloring", \
-         VSC_CLI__OPTION_TYPE__BOOLEAN, TRUE, FALSE }
+         VSC_CLI__OPTION_TYPE__BOOLEAN, VSC_CLI__OPTION_FLAG__TAGGED }
 
 #ifdef __cplusplus
 extern "C" {
index 952229c..0b274dc 100644 (file)
@@ -28,11 +28,18 @@ extern "C" {
 #endif
 
 enum VscCliOptionType {
-       VSC_CLI__OPTION_TYPE__BOOLEAN = 0,
+       VSC_CLI__OPTION_TYPE__UNDEFINED = 0,
+       VSC_CLI__OPTION_TYPE__BOOLEAN,
        VSC_CLI__OPTION_TYPE__NUMBER,
        VSC_CLI__OPTION_TYPE__STRING,
 };
 
+enum VscCliOptionFlag {
+       VSC_CLI__OPTION_FLAG__NONE = 0,
+       VSC_CLI__OPTION_FLAG__TAGGED = 1,
+       VSC_CLI__OPTION_FLAG__REQUIRED = 2,
+};
+
 struct VscCliOption;
 struct VscCliCommandInfo;
 
@@ -52,8 +59,7 @@ struct VscCliOptionInfo {
        const char* long_name;
        const char* help;
        enum VscCliOptionType type;
-       int tagged;
-       int required;
+       int flags;
 };
 
 struct VscCliOption {
index 7cf1081..1d50d70 100644 (file)
@@ -270,9 +270,9 @@ _login (struct VscError *error, const struct VscCliCommandInfo *command_info,
 
 static const struct VscCliOptionInfo _login_option_infos[] = {
        { -1, "username", "Username for the remote system",
-         VSC_CLI__OPTION_TYPE__STRING, FALSE, TRUE },
+         VSC_CLI__OPTION_TYPE__STRING, VSC_CLI__OPTION_FLAG__REQUIRED },
        { -1, "password", "Password for the remote system",
-         VSC_CLI__OPTION_TYPE__STRING, FALSE, FALSE },
+         VSC_CLI__OPTION_TYPE__STRING, VSC_CLI__OPTION_FLAG__NONE },
        VSC_CLI__NULL__OPTION_INFO,
 };
 
@@ -769,7 +769,7 @@ vsc_remote_default_pack (struct VscError *error,
                                goto cleanup;
                        }
                } else if (option_info->type == VSC_CLI__OPTION_TYPE__BOOLEAN &&
-                          option_info->required) {
+                          option_info->flags & VSC_CLI__OPTION_FLAG__REQUIRED) {
                        value = xmlrpc_bool_new (&env, FALSE);
                } else {
                        continue;