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

cli: add 'help' for second level commands (bgo #698237) (rh #1034119)

In addition to 'nmcli connection help', you can now use:
nmcli con up help
nmcli con down help
nmcli dev wifi help
etc.

The help option can also be in the form of --help/-h, or even shortened.

https://bugzilla.gnome.org/show_bug.cgi?id=698237
https://bugzilla.redhat.com/show_bug.cgi?id=1034119
parent a0e7926d
This diff is collapsed.
......@@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 - 2013 Red Hat, Inc.
* (C) Copyright 2010 - 2014 Red Hat, Inc.
*/
#include "config.h"
......@@ -273,24 +273,127 @@ usage (void)
fprintf (stderr,
_("Usage: nmcli device { COMMAND | help }\n\n"
#if WITH_WIMAX
" COMMAND := { status | show | connect | disconnect | wifi | wimax }\n\n"
"COMMAND := { status | show | connect | disconnect | wifi | wimax }\n\n"
#else
" COMMAND := { status | show | connect | disconnect | wifi }\n\n"
"COMMAND := { status | show | connect | disconnect | wifi }\n\n"
#endif
" status\n\n"
" show [<ifname>]\n\n"
" connect <ifname>\n\n"
" disconnect <ifname>\n\n"
" wifi [list [ifname <ifname>] [bssid <BSSID>]]\n\n"
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>] [bssid <BSSID>] [name <name>]\n\n"
" [private yes|no]\n\n"
" wifi rescan [[ifname] <ifname>]\n\n"
" status\n\n"
" show [<ifname>]\n\n"
" connect <ifname>\n\n"
" disconnect <ifname>\n\n"
" wifi [list [ifname <ifname>] [bssid <BSSID>]]\n\n"
" wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n"
" [bssid <BSSID>] [name <name>] [private yes|no]\n\n"
" wifi rescan [[ifname] <ifname>]\n\n"
#if WITH_WIMAX
" wimax [list [ifname <ifname>] [nsp <name>]]\n\n"
" wimax [list [ifname <ifname>] [nsp <name>]]\n\n"
#endif
));
}
static void
usage_device_status (void)
{
fprintf (stderr,
_("Usage: nmcli device status { help }\n"
"\n"
"Show status for all devices.\n"
"By default, the following columns are shown:\n"
" DEVICE - interface name\n"
" TYPE - device type\n"
" STATE - device state\n"
" CONNECTION - connection activated on device (if any)\n"
"Displayed columns can be changed using '--fields' global option. 'status' is\n"
"the default command, which means 'nmcli device' calls 'nmcli device status'.\n\n"));
}
static void
usage_device_show (void)
{
fprintf (stderr,
_("Usage: nmcli device show { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [<ifname>]\n"
"\n"
"Show details of device(s).\n"
"The command lists details for all devices, or for a given device.\n\n"));
}
static void
usage_device_connect (void)
{
fprintf (stderr,
_("Usage: nmcli device connect { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := <ifname>\n"
"\n"
"Connect the device.\n"
"NetworkManager will try to find a suitable connection that will be activated.\n"
"It will also consider connections that are not set to auto-connect.\n\n"));
}
static void
usage_device_disconnect (void)
{
fprintf (stderr,
_("Usage: nmcli device disconnect { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := <ifname>\n"
"\n"
"Disconnect the device.\n"
"The command disconnects the device and prevents it from auto-activating\n"
"further connections without user/manual intervention.\n\n"));
}
static void
usage_device_wifi (void)
{
fprintf (stderr,
_("Usage: nmcli device wifi { ARGUMENTS | help }\n"
"\n"
"Perform operation on Wi-Fi devices.\n"
"\n"
"ARGUMENTS := [list [ifname <ifname>] [bssid <BSSID>]]\n"
"\n"
"List available Wi-Fi access points. The 'ifname' and 'bssid' options can be\n"
"used to list APs for a particular interface, or with a specific BSSID.\n"
"\n"
"ARGUMENTS := connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n"
" [bssid <BSSID>] [name <name>] [private yes|no]\n"
"\n"
"Connect to a Wi-Fi network specified by SSID or BSSID. The command creates\n"
"a new connection and then activates it on a device. This is a command-line\n"
"counterpart of clicking an SSID in a GUI client. The command always creates\n"
"a new connection and thus it is mainly useful for connecting to new Wi-Fi\n"
"networks. If a connection for the network already exists, it is better to\n"
"bring up the existing profile as follows: nmcli con up id <name>. Note that\n"
"only open, WEP and WPA-PSK networks are supported at the moment. It is also\n"
"assumed that IP configuration is obtained via DHCP.\n"
"\n"
"ARGUMENTS := rescan [[ifname] <ifname>]\n"
"\n"
"Request that NetworkManager immediately re-scan for available access points.\n"
"NetworkManager scans Wi-Fi networks periodically, but in some cases it might\n"
"be useful to start scanning manually. Note that this command does not show\n"
"the APs, use 'nmcli device wifi list' for that.\n\n"));
}
#if WITH_WIMAX
static void
usage_device_wimax (void)
{
fprintf (stderr,
_("Usage: nmcli device wimax { ARGUMENTS | help }\n"
"\n"
"Perform operation on WiMAX devices.\n"
"\n"
"ARGUMENTS := [list [ifname <ifname>] [nsp <name>]]\n"
"\n"
"List available WiMAX NSPs. The 'ifname' and 'nsp' options can be used to\n"
"list networks for a particular interface, or with a specific NSP.\n\n"));
}
#endif
/* quit main loop */
static void
quit (void)
......@@ -2454,30 +2557,55 @@ do_devices (NmCli *nmc, int argc, char **argv)
if (argc > 0) {
if (nmc_arg_is_help (*argv)) {
usage ();
goto usage_exit;
}
else if (matches (*argv, "status") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_device_status ();
goto usage_exit;
}
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
nmc->return_value = do_devices_status (nmc, argc-1, argv+1);
}
else if (matches (*argv, "show") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_device_show ();
goto usage_exit;
}
if (!nmc->mode_specified)
nmc->multiline_output = TRUE; /* multiline mode is default for 'device show' */
nmc->return_value = do_devices_show (nmc, argc-1, argv+1);
}
else if (matches (*argv, "connect") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_device_connect ();
goto usage_exit;
}
nmc->return_value = do_device_connect (nmc, argc-1, argv+1);
}
else if (matches (*argv, "disconnect") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_device_disconnect ();
goto usage_exit;
}
nmc->return_value = do_device_disconnect (nmc, argc-1, argv+1);
}
else if (matches (*argv, "wifi") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_device_wifi ();
goto usage_exit;
}
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
nmc->return_value = do_device_wifi (nmc, argc-1, argv+1);
}
#if WITH_WIMAX
else if (matches (*argv, "wimax") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_device_wimax ();
goto usage_exit;
}
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error;
nmc->return_value = do_device_wimax (nmc, argc-1, argv+1);
......@@ -2490,6 +2618,7 @@ do_devices (NmCli *nmc, int argc, char **argv)
}
}
usage_exit:
return nmc->return_value;
opt_error:
......
......@@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2010 - 2013 Red Hat, Inc.
* (C) Copyright 2010 - 2014 Red Hat, Inc.
*/
#include "config.h"
......@@ -93,12 +93,57 @@ usage_general (void)
{
fprintf (stderr,
_("Usage: nmcli general { COMMAND | help }\n\n"
" COMMAND := { status | hostname | permissions | logging }\n\n"
" status\n\n"
" hostname [<hostname>]\n\n"
" permissions\n\n"
" logging [level <log level>] [domains <log domains>]\n\n"
));
"COMMAND := { status | hostname | permissions | logging }\n\n"
" status\n\n"
" hostname [<hostname>]\n\n"
" permissions\n\n"
" logging [level <log level>] [domains <log domains>]\n\n"));
}
static void
usage_general_status (void)
{
fprintf (stderr,
_("Usage: nmcli general status { help }\n"
"\n"
"Show overall status of NetworkManager.\n"
"'status' is the default action, which means 'nmcli gen' calls 'nmcli gen status'\n\n"));
}
static void
usage_general_hostname (void)
{
fprintf (stderr,
_("Usage: nmcli general hostname { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [<hostname>]\n"
"\n"
"Get or change persistent system hostname.\n"
"With no arguments, this prints currently configured hostname. When you pass\n"
"a hostname, NetworkManager will set it as the new persistent system hostname.\n\n"));
}
static void
usage_general_permissions (void)
{
fprintf (stderr,
_("Usage: nmcli general permissions { help }\n"
"\n"
"Show caller permissions for authenticated operations.\n\n"));
}
static void
usage_general_logging (void)
{
fprintf (stderr,
_("Usage: nmcli general logging { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [level <log level>] [domains <log domains>]\n"
"\n"
"Get or change NetworkManager logging level and domains.\n"
"Without any argument current logging level and domains are shown. In order to\n"
"change logging state, provide level and/or domain. Please refer to the man page\n"
"for the list of possible logging domains.\n\n"));
}
static void
......@@ -106,11 +151,41 @@ usage_networking (void)
{
fprintf (stderr,
_("Usage: nmcli networking { COMMAND | help }\n\n"
" COMMAND := { on | off | connectivity }\n\n"
" on\n\n"
" off\n\n"
" connectivity [check]\n\n"
));
"COMMAND := { [ on | off | connectivity ] }\n\n"
" on\n\n"
" off\n\n"
" connectivity [check]\n\n"));
}
static void
usage_networking_on (void)
{
fprintf (stderr,
_("Usage: nmcli networking on { help }\n"
"\n"
"Switch networking on.\n\n"));
}
static void
usage_networking_off (void)
{
fprintf (stderr,
_("Usage: nmcli networking off { help }\n"
"\n"
"Switch networking off.\n\n"));
}
static void
usage_networking_connectivity (void)
{
fprintf (stderr,
_("Usage: nmcli networking connectivity { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [check]\n"
"\n"
"Get network connectivity state.\n"
"The optional 'check' argument makes NetworkManager re-check the connectivity.\n\n"));
}
static void
......@@ -119,15 +194,61 @@ usage_radio (void)
fprintf (stderr,
_("Usage: nmcli radio { COMMAND | help }\n\n"
#if WITH_WIMAX
" COMMAND := { all | wifi | wwan | wimax }\n\n"
" all | wifi | wwan | wimax [ on | off ]\n\n"
"COMMAND := { all | wifi | wwan | wimax }\n\n"
" all | wifi | wwan | wimax [ on | off ]\n\n"
#else
" COMMAND := { all | wifi | wwan }\n\n"
" all | wifi | wwan [ on | off ]\n\n"
"COMMAND := { all | wifi | wwan }\n\n"
" all | wifi | wwan [ on | off ]\n\n"
#endif
));
}
static void
usage_radio_all (void)
{
fprintf (stderr,
_("Usage: nmcli radio all { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [on | off]\n"
"\n"
"Get status of all radio switches, or turn them on/off.\n\n"));
}
static void
usage_radio_wifi (void)
{
fprintf (stderr,
_("Usage: nmcli radio wifi { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [on | off]\n"
"\n"
"Get status of Wi-Fi radio switch, or turn it on/off.\n\n"));
}
static void
usage_radio_wwan (void)
{
fprintf (stderr,
_("Usage: nmcli radio wwan { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [on | off]\n"
"\n"
"Get status of mobile broadband radio switch, or turn it on/off.\n\n"));
}
#if WITH_WIMAX
static void
usage_radio_wimax (void)
{
fprintf (stderr,
_("Usage: nmcli radio wimax { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [on | off]\n"
"\n"
"Get status of WiMAX radio switch, or turn it on/off.\n\n"));
}
#endif
/* quit main loop */
static void
quit (void)
......@@ -470,6 +591,10 @@ do_general (NmCli *nmc, int argc, char **argv)
usage_general ();
}
else if (matches (*argv, "status") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_general_status ();
goto finish;
}
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
......@@ -480,6 +605,11 @@ do_general (NmCli *nmc, int argc, char **argv)
else if (matches (*argv, "hostname") == 0) {
NMRemoteSettings *rem_settings;
if (nmc_arg_is_help (*(argv+1))) {
usage_general_hostname ();
goto finish;
}
/* get system settings */
if (!(rem_settings = nm_remote_settings_new (NULL))) {
g_string_printf (nmc->return_text, _("Error: Could not get system settings."));
......@@ -507,6 +637,10 @@ do_general (NmCli *nmc, int argc, char **argv)
}
}
else if (matches (*argv, "permissions") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_general_permissions ();
goto finish;
}
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
......@@ -515,6 +649,10 @@ do_general (NmCli *nmc, int argc, char **argv)
show_nm_permissions (nmc);
}
else if (matches (*argv, "logging") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_general_logging ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) {
/* no arguments -> get logging level and domains */
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
......@@ -622,6 +760,10 @@ do_networking (NmCli *nmc, int argc, char **argv)
if (nmc_arg_is_help (*argv)) {
usage_networking ();
} else if (matches (*argv, "connectivity") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_networking_connectivity ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) {
/* no arguments -> get current state */
show_networking_connectivity (nmc);
......@@ -642,6 +784,13 @@ do_networking (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
}
} else if (nmc_switch_parse_on_off (nmc, *(argv-1), *argv, &enable_flag)) {
if (nmc_arg_is_help (*(argv+1))) {
if (enable_flag)
usage_networking_on ();
else
usage_networking_off ();
goto finish;
}
nmc->get_client (nmc); /* create NMClient */
nm_client_networking_set_enabled (nmc->client, enable_flag);
......@@ -652,6 +801,7 @@ do_networking (NmCli *nmc, int argc, char **argv)
}
}
finish:
quit ();
return nmc->return_value;
}
......@@ -680,6 +830,10 @@ do_radio (NmCli *nmc, int argc, char **argv)
usage_radio ();
}
else if (matches (*argv, "all") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_all ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) {
/* no argument, show all radio switches */
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
......@@ -700,6 +854,10 @@ do_radio (NmCli *nmc, int argc, char **argv)
}
}
else if (matches (*argv, "wifi") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_wifi ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WiFi state */
nmc_switch_show (nmc, NMC_FIELDS_NM_WIFI, _("Wi-Fi radio switch"));
......@@ -712,6 +870,10 @@ do_radio (NmCli *nmc, int argc, char **argv)
}
}
else if (matches (*argv, "wwan") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_wwan ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WWAN (mobile broadband) state */
nmc_switch_show (nmc, NMC_FIELDS_NM_WWAN, _("WWAN radio switch"));
......@@ -725,6 +887,10 @@ do_radio (NmCli *nmc, int argc, char **argv)
}
#if WITH_WIMAX
else if (matches (*argv, "wimax") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_wimax ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WiMAX state */
nmc_switch_show (nmc, NMC_FIELDS_NM_WIMAX, _("WiMAX radio switch"));
......
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