summary refs log tree commit diff
path: root/clients/cli/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'clients/cli/utils.c')
-rw-r--r--clients/cli/utils.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/clients/cli/utils.c b/clients/cli/utils.c
index dfd002ed..3cc836d8 100644
--- a/clients/cli/utils.c
+++ b/clients/cli/utils.c
@@ -407,7 +407,10 @@ nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error)
 
 	if (g_strcmp0 (str, "o") == 0) {
 		g_set_error (error, 1, 0,
-		             _("'%s' is ambiguous (on x off)"), str);
+		             /* Translators: the first %s is the partial value entered by
+		              * the user, the second %s a list of compatible values.
+		              */
+		             _("'%s' is ambiguous (%s)"), str, "on x off");
 		return FALSE;
 	}
 
@@ -424,6 +427,39 @@ nmc_string_to_bool (const char *str, gboolean *val_bool, GError **error)
 	return TRUE;
 }
 
+gboolean
+nmc_string_to_tristate (const char *str, NMCTriStateValue *val, GError **error)
+{
+	const char *s_true[] = { "true", "yes", "on", NULL };
+	const char *s_false[] = { "false", "no", "off", NULL };
+	const char *s_unknown[] = { "unknown", NULL };
+
+	g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+
+	if (g_strcmp0 (str, "o") == 0) {
+		g_set_error (error, 1, 0,
+		             /* Translators: the first %s is the partial value entered by
+		              * the user, the second %s a list of compatible values.
+		              */
+		             _("'%s' is ambiguous (%s)"), str, "on x off");
+		return FALSE;
+	}
+
+	if (nmc_string_is_valid (str, s_true, NULL))
+		*val = NMC_TRI_STATE_YES;
+	else if (nmc_string_is_valid (str, s_false, NULL))
+		*val = NMC_TRI_STATE_NO;
+	else if (nmc_string_is_valid (str, s_unknown, NULL))
+		*val = NMC_TRI_STATE_UNKNOWN;
+	else {
+		g_set_error (error, 1, 0,
+		             _("'%s' is not valid; use [%s], [%s] or [%s]"),
+		             str, "true, yes, on", "false, no, off", "unknown");
+		return FALSE;
+	}
+	return TRUE;
+}
+
 /*
  * Ask user for input and return the string.
  * The caller is responsible for freeing the returned string.