Commit 31970798 authored by Jiří Klimeš's avatar Jiří Klimeš

cli: add NMC_RESULT_ERROR_USER_INPUT code for bad invocation of nmcli

parent 8846bd83
......@@ -220,7 +220,7 @@ do_connections_list (NmCli *nmc, int argc, char **argv)
else
g_string_printf (nmc->return_text, _("Error: 'con list': %s; allowed fields: %s"), error->message, NMC_FIELDS_CON_LIST_ALL);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -246,7 +246,7 @@ do_connections_list (NmCli *nmc, int argc, char **argv)
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
valid_param_specified = TRUE;
......@@ -290,7 +290,7 @@ do_connections_list (NmCli *nmc, int argc, char **argv)
if (!valid_param_specified) {
g_string_printf (nmc->return_text, _("Error: no valid parameter specified."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
error:
......@@ -399,7 +399,7 @@ do_connections_status (NmCli *nmc, int argc, char **argv)
else
g_string_printf (nmc->return_text, _("Error: 'con status': %s; allowed fields: %s"), error->message, NMC_FIELDS_CON_STATUS_ALL);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1081,7 +1081,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1097,7 +1097,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
else if (strcmp (*argv, "iface") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1106,7 +1106,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
else if (strcmp (*argv, "ap") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1117,7 +1117,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
} else if (strcmp (*argv, "--timeout") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1125,7 +1125,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
nmc->timeout = strtol (*argv, NULL, 10);
if (errno || nmc->timeout < 0) {
g_string_printf (nmc->return_text, _("Error: timeout value '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
} else {
......@@ -1138,7 +1138,7 @@ do_connection_up (NmCli *nmc, int argc, char **argv)
if (!id_specified) {
g_string_printf (nmc->return_text, _("Error: id or uuid has to be specified."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1199,7 +1199,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1225,7 +1225,7 @@ do_connection_down (NmCli *nmc, int argc, char **argv)
if (!id_specified) {
g_string_printf (nmc->return_text, _("Error: id or uuid has to be specified."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1284,18 +1284,18 @@ get_connections_cb (NMSettingsInterface *settings, gpointer user_data)
if (args->argc == 0) {
if (!nmc_terse_option_check (args->nmc->print_output, args->nmc->required_fields, &error))
goto error;
goto opt_error;
args->nmc->return_value = do_connections_list (args->nmc, args->argc, args->argv);
} else {
if (matches (*args->argv, "list") == 0) {
if (!nmc_terse_option_check (args->nmc->print_output, args->nmc->required_fields, &error))
goto error;
goto opt_error;
args->nmc->return_value = do_connections_list (args->nmc, args->argc-1, args->argv+1);
}
else if (matches(*args->argv, "status") == 0) {
if (!nmc_terse_option_check (args->nmc->print_output, args->nmc->required_fields, &error))
goto error;
goto opt_error;
args->nmc->return_value = do_connections_status (args->nmc, args->argc-1, args->argv+1);
}
else if (matches(*args->argv, "up") == 0) {
......@@ -1310,7 +1310,7 @@ get_connections_cb (NMSettingsInterface *settings, gpointer user_data)
} else {
usage ();
g_string_printf (args->nmc->return_text, _("Error: 'con' command '%s' is not valid."), *args->argv);
args->nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
args->nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
args->nmc->should_wait = FALSE;
}
}
......@@ -1319,9 +1319,9 @@ get_connections_cb (NMSettingsInterface *settings, gpointer user_data)
quit ();
return;
error:
opt_error:
g_string_printf (args->nmc->return_text, _("Error: %s."), error->message);
args->nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
args->nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
args->nmc->should_wait = FALSE;
g_error_free (error);
quit ();
......
......@@ -654,7 +654,7 @@ do_devices_status (NmCli *nmc, int argc, char **argv)
else
g_string_printf (nmc->return_text, _("Error: 'dev status': %s; allowed fields: %s"), error->message, NMC_FIELDS_DEV_STATUS_ALL);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -688,7 +688,7 @@ do_devices_list (NmCli *nmc, int argc, char **argv)
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: '%s' argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -805,7 +805,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -815,7 +815,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
} else if (strcmp (*argv, "--timeout") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -823,7 +823,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
nmc->timeout = strtol (*argv, NULL, 10);
if (errno || nmc->timeout < 0) {
g_string_printf (nmc->return_text, _("Error: timeout value '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -837,7 +837,7 @@ do_device_disconnect (NmCli *nmc, int argc, char **argv)
if (!iface_specified) {
g_string_printf (nmc->return_text, _("Error: iface has to be specified."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -913,14 +913,14 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
if (strcmp (*argv, "iface") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
iface = *argv;
} else if (strcmp (*argv, "hwaddr") == 0) {
if (next_arg (&argc, &argv) != 0) {
g_string_printf (nmc->return_text, _("Error: %s argument is missing."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
hwaddr_user = *argv;
......@@ -954,7 +954,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv)
else
g_string_printf (nmc->return_text, _("Error: 'dev wifi': %s; allowed fields: %s"), error->message, NMC_FIELDS_DEV_WIFI_LIST_ALL);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto error;
}
......@@ -1074,7 +1074,7 @@ do_device_wifi (NmCli *nmc, int argc, char **argv)
}
else {
g_string_printf (nmc->return_text, _("Error: 'dev wifi' command '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
}
......@@ -1093,14 +1093,14 @@ do_devices (NmCli *nmc, int argc, char **argv)
if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto error;
goto opt_error;
nmc->return_value = do_devices_status (nmc, 0, NULL);
}
if (argc > 0) {
if (matches (*argv, "status") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto error;
goto opt_error;
nmc->return_value = do_devices_status (nmc, argc-1, argv+1);
}
else if (matches (*argv, "list") == 0) {
......@@ -1111,7 +1111,7 @@ do_devices (NmCli *nmc, int argc, char **argv)
}
else if (matches (*argv, "wifi") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto error;
goto opt_error;
nmc->return_value = do_device_wifi (nmc, argc-1, argv+1);
}
else if (strcmp (*argv, "help") == 0) {
......@@ -1119,16 +1119,16 @@ do_devices (NmCli *nmc, int argc, char **argv)
}
else {
g_string_printf (nmc->return_text, _("Error: 'dev' command '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
}
end:
return nmc->return_value;
error:
opt_error:
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
g_error_free (error);
return nmc->return_value;
}
......@@ -126,7 +126,7 @@ show_nm_status (NmCli *nmc)
else
g_string_printf (nmc->return_text, _("Error: 'nm status': %s; allowed fields: %s"), error->message, NMC_FIELDS_NM_STATUS_ALL);
g_error_free (error);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
......@@ -176,14 +176,14 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
if (argc == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto error;
goto opt_error;
nmc->return_value = show_nm_status (nmc);
}
if (argc > 0) {
if (matches (*argv, "status") == 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto error;
goto opt_error;
nmc->return_value = show_nm_status (nmc);
}
else if (matches (*argv, "sleep") == 0) {
......@@ -196,11 +196,11 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WiFi state */
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto error;
goto opt_error;
if (nmc->required_fields && strcasecmp (nmc->required_fields, "WIFI")) {
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here; allowed fields: %s"),
nmc->required_fields, NMC_FIELDS_NM_WIFI);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->allowed_fields = nmc_fields_nm_status;
......@@ -218,7 +218,7 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
enable_wifi = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'wifi' parameter: '%s'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nm_client_wireless_set_enabled (nmc->client, enable_wifi);
......@@ -227,12 +227,12 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
else if (matches (*argv, "wwan") == 0) {
if (next_arg (&argc, &argv) != 0) {
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto error;
goto opt_error;
/* no argument, show current WWAN state */
if (nmc->required_fields && strcasecmp (nmc->required_fields, "WWAN")) {
g_string_printf (nmc->return_text, _("Error: '--fields' value '%s' is not valid here; allowed fields: %s"),
nmc->required_fields, NMC_FIELDS_NM_WWAN);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nmc->allowed_fields = nmc_fields_nm_status;
......@@ -250,7 +250,7 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
enable_wwan = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: invalid 'wwan' parameter: '%s'."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
goto end;
}
nm_client_wwan_set_enabled (nmc->client, enable_wwan);
......@@ -261,7 +261,7 @@ do_network_manager (NmCli *nmc, int argc, char **argv)
}
else {
g_string_printf (nmc->return_text, _("Error: 'nm' command '%s' is not valid."), *argv);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
}
......@@ -269,10 +269,10 @@ end:
quit ();
return nmc->return_value;
error:
opt_error:
quit ();
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
g_error_free (error);
return nmc->return_value;
}
......@@ -106,8 +106,8 @@ do_cmd (NmCli *nmc, const char *argv0, int argc, char **argv)
return c->func (nmc, argc-1, argv+1);
}
g_string_printf (nmc->return_text, _("Object '%s' is unknown, try 'nmcli help'."), argv0);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_string_printf (nmc->return_text, _("Error: Object '%s' is unknown, try 'nmcli help'."), argv0);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
......@@ -136,26 +136,26 @@ parse_command_line (NmCli *nmc, int argc, char **argv)
opt++;
if (matches (opt, "-terse") == 0) {
if (nmc->print_output == NMC_PRINT_TERSE) {
g_string_printf (nmc->return_text, _("Option '--terse' is specified the second time."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_string_printf (nmc->return_text, _("Error: Option '--terse' is specified the second time."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
else if (nmc->print_output == NMC_PRINT_PRETTY) {
g_string_printf (nmc->return_text, _("Option '--terse' is mutually exclusive with '--pretty'."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_string_printf (nmc->return_text, _("Error: Option '--terse' is mutually exclusive with '--pretty'."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
else
nmc->print_output = NMC_PRINT_TERSE;
} else if (matches (opt, "-pretty") == 0) {
if (nmc->print_output == NMC_PRINT_PRETTY) {
g_string_printf (nmc->return_text, _("Option '--pretty' is specified the second time."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_string_printf (nmc->return_text, _("Error: Option '--pretty' is specified the second time."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
else if (nmc->print_output == NMC_PRINT_TERSE) {
g_string_printf (nmc->return_text, _("Option '--pretty' is mutually exclusive with '--terse'."));
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_string_printf (nmc->return_text, _("Error: Option '--pretty' is mutually exclusive with '--terse'."));
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
else
......@@ -166,7 +166,7 @@ parse_command_line (NmCli *nmc, int argc, char **argv)
next_arg (&argc, &argv);
if (argc <= 1) {
g_string_printf (nmc->return_text, _("Error: missing argument for '%s' option."), opt);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
if (!strcmp (argv[1], "yes"))
......@@ -175,14 +175,14 @@ parse_command_line (NmCli *nmc, int argc, char **argv)
nmc->escape_values = FALSE;
else {
g_string_printf (nmc->return_text, _("Error: '%s' is not valid argument for '%s' option."), argv[1], opt);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
} else if (matches (opt, "-fields") == 0) {
next_arg (&argc, &argv);
if (argc <= 1) {
g_string_printf (nmc->return_text, _("Error: fields for '%s' options are missing."), opt);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
nmc->required_fields = g_strdup (argv[1]);
......@@ -193,8 +193,8 @@ parse_command_line (NmCli *nmc, int argc, char **argv)
usage (base);
return NMC_RESULT_SUCCESS;
} else {
g_string_printf (nmc->return_text, _("Option '%s' is unknown, try 'nmcli -help'."), opt);
nmc->return_value = NMC_RESULT_ERROR_UNKNOWN;
g_string_printf (nmc->return_text, _("Error: Option '%s' is unknown, try 'nmcli -help'."), opt);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
return nmc->return_value;
}
argc--;
......
......@@ -32,25 +32,28 @@ typedef enum {
NMC_RESULT_SUCCESS = 0,
/* Unknown / unspecified error */
NMC_RESULT_ERROR_UNKNOWN,
NMC_RESULT_ERROR_UNKNOWN = 1,
/* Wrong invocation of nmcli */
NMC_RESULT_ERROR_USER_INPUT = 2,
/* A timeout expired */
NMC_RESULT_ERROR_TIMEOUT_EXPIRED,
NMC_RESULT_ERROR_TIMEOUT_EXPIRED = 3,
/* Error in connection activation */
NMC_RESULT_ERROR_CON_ACTIVATION,
NMC_RESULT_ERROR_CON_ACTIVATION = 4,
/* Error in connection deactivation */
NMC_RESULT_ERROR_CON_DEACTIVATION,
NMC_RESULT_ERROR_CON_DEACTIVATION = 5,
/* Error in device disconnect */
NMC_RESULT_ERROR_DEV_DISCONNECT
NMC_RESULT_ERROR_DEV_DISCONNECT = 6
} NMCResultCode;
typedef enum {
NMC_PRINT_TERSE = 0,
NMC_PRINT_NORMAL,
NMC_PRINT_PRETTY
NMC_PRINT_NORMAL = 1,
NMC_PRINT_PRETTY = 2
} NMCPrintOutput;
/* === Output fields === */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment