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
This commit is contained in:
Jiří Klimeš
2013-12-18 14:49:06 +01:00
parent a0e7926df4
commit e44bb5e6fc
3 changed files with 565 additions and 118 deletions

View File

@@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 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" #include "config.h"
@@ -252,102 +252,218 @@ static void
usage (void) usage (void)
{ {
fprintf (stderr, fprintf (stderr,
_("Usage: nmcli connection { COMMAND | help }\n" _("Usage: nmcli connection { COMMAND | help }\n\n"
" COMMAND := { show | up | down | add | modify | edit | delete | reload | load }\n\n" "COMMAND := { show | up | down | add | modify | edit | delete | reload | load }\n\n"
" show configured [[ id | uuid | path ] <ID>]\n\n" " show configured [[id | uuid | path] <ID>]\n"
" show active [[ id | uuid | path | apath ] <ID>]\n\n" " show active [[id | uuid | path | apath] <ID>]\n\n"
#if WITH_WIMAX #if WITH_WIMAX
" up [[ id | uuid | path ] <ID>] [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n\n" " up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n\n"
#else #else
" up [[ id | uuid | path ] <ID>] [ifname <ifname>] [ap <BSSID>]\n\n" " up [[id | uuid | path] <ID>] [ifname <ifname>] [ap <BSSID>]\n\n"
#endif #endif
" down [ id | uuid | path | apath ] <ID>\n\n" " down [id | uuid | path | apath] <ID>\n\n"
" add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n" " add COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
" modify [ id | uuid | path ] <ID> <setting>.<property> <value>\n\n" " modify [id | uuid | path] <ID> <setting>.<property> <value>\n\n"
" edit [ id | uuid | path ] <ID> | [type <new_con_type>] [con-name <new_con_name>]\n\n" " edit [id | uuid | path] <ID>\n"
" delete [ id | uuid | path ] <ID>\n\n" " edit [type <new_con_type>] [con-name <new_con_name>]\n\n"
" reload\n\n" " delete [id | uuid | path] <ID>\n\n"
" load <filename> [ <filename>... ]\n\n\n" " reload\n\n"
)); " load <filename> [ <filename>... ]\n\n"));
}
static void
usage_connection_show (void)
{
fprintf (stderr,
_("Usage: nmcli connection show { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := active [[id | uuid | path | apath] <ID>]\n"
"\n"
"Show connections which are currently used by a device to connect to a network.\n"
"Without a parameter, all active connections are listed. When <ID> is provided,\n"
"the connection details are displayed instead.\n"
"\n"
"ARGUMENTS := configured [[id | uuid | path] <ID>]\n"
"\n"
"Show in-memory and on-disk connections, some of which may also be active if\n"
"a device is using that connection profile. Without a parameter, all profiles\n"
"are listed. When <ID> is provided, the profile details are displayed instead.\n\n"));
}
static void
usage_connection_up (void)
{
fprintf (stderr,
_("Usage: nmcli connection up { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [id | uuid | path] <ID> [ifname <ifname>] [ap <BSSID>] [nsp <name>]\n"
"\n"
"Activate a connection on a device. The profile to activate is identified by its\n"
"name, UUID or D-Bus path.\n"
"\n"
"ARGUMENTS := ifname <ifname> [ap <BSSID>] [nsp <name>]\n"
"\n"
"Activate a device with a connection. The connection profile is selected\n"
"automatically by NetworkManager.\n"
"\n"
"ifname - specifies the device to active the connection on\n"
"ap - specifies AP to connect to (only valid for Wi-Fi)\n"
"nsp - specifies NSP to connect to (only valid for WiMAX)\n\n"));
}
static void
usage_connection_down (void)
{
fprintf (stderr,
_("Usage: nmcli connection down { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [id | uuid | path | apath] <ID>\n"
"\n"
"Deactivate a connection from a device (without preventing the device from\n"
"further auto-activation). The profile to deactivate is identified by its name,\n"
"UUID or D-Bus path.\n\n"));
} }
static void static void
usage_connection_add (void) usage_connection_add (void)
{ {
fprintf (stderr, fprintf (stderr,
_("Usage: nmcli connection add { OPTIONS | help }\n" _("Usage: nmcli connection add { ARGUMENTS | help }\n"
" OPTIONS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n" "\n"
" COMMON_OPTIONS:\n" "ARGUMENTS := COMMON_OPTIONS TYPE_SPECIFIC_OPTIONS IP_OPTIONS\n\n"
" type <type>\n" " COMMON_OPTIONS:\n"
" ifname <interface name> | \"*\"\n" " type <type>\n"
" [con-name <connection name>]\n" " ifname <interface name> | \"*\"\n"
" [autoconnect yes|no]\n\n" " [con-name <connection name>]\n"
" TYPE_SPECIFIC_OPTIONS:\n" " [autoconnect yes|no]\n\n"
" ethernet: [mac <MAC address>]\n" " TYPE_SPECIFIC_OPTIONS:\n"
" [cloned-mac <cloned MAC address>]\n" " ethernet: [mac <MAC address>]\n"
" [mtu <MTU>]\n\n" " [cloned-mac <cloned MAC address>]\n"
" wifi: ssid <SSID>\n" " [mtu <MTU>]\n\n"
" [mac <MAC address>]\n" " wifi: ssid <SSID>\n"
" [cloned-mac <cloned MAC address>]\n" " [mac <MAC address>]\n"
" [mtu <MTU>]\n\n" " [cloned-mac <cloned MAC address>]\n"
" wimax: [mac <MAC address>]\n" " [mtu <MTU>]\n\n"
" [nsp <NSP>]\n\n" " wimax: [mac <MAC address>]\n"
" pppoe: username <PPPoE username>\n" " [nsp <NSP>]\n\n"
" [password <PPPoE password>]\n" " pppoe: username <PPPoE username>\n"
" [service <PPPoE service name>]\n" " [password <PPPoE password>]\n"
" [mtu <MTU>]\n" " [service <PPPoE service name>]\n"
" [mac <MAC address>]\n\n" " [mtu <MTU>]\n"
" gsm: apn <APN>\n" " [mac <MAC address>]\n\n"
" [user <username>]\n" " gsm: apn <APN>\n"
" [password <password>]\n\n" " [user <username>]\n"
" cdma: [user <username>]\n" " [password <password>]\n\n"
" [password <password>]\n\n" " cdma: [user <username>]\n"
" infiniband: [mac <MAC address>]\n" " [password <password>]\n\n"
" [mtu <MTU>]\n" " infiniband: [mac <MAC address>]\n"
" [transport-mode datagram | connected]\n" " [mtu <MTU>]\n"
" [parent <ifname>]\n" " [transport-mode datagram | connected]\n"
" [p-key <IPoIB P_Key>]\n\n" " [parent <ifname>]\n"
" bluetooth: [addr <bluetooth address>]\n" " [p-key <IPoIB P_Key>]\n\n"
" [bt-type panu|dun-gsm|dun-cdma]\n\n" " bluetooth: [addr <bluetooth address>]\n"
" vlan: dev <parent device (connection UUID, ifname, or MAC)>\n" " [bt-type panu|dun-gsm|dun-cdma]\n\n"
" id <VLAN ID>\n" " vlan: dev <parent device (connection UUID, ifname, or MAC)>\n"
" [flags <VLAN flags>]\n" " id <VLAN ID>\n"
" [ingress <ingress priority mapping>]\n" " [flags <VLAN flags>]\n"
" [egress <egress priority mapping>]\n" " [ingress <ingress priority mapping>]\n"
" [mtu <MTU>]\n\n" " [egress <egress priority mapping>]\n"
" bond: [mode balance-rr (0) | active-backup (1) | balance-xor (2) | broadcast (3) |\n" " [mtu <MTU>]\n\n"
" 802.3ad (4) | balance-tlb (5) | balance-alb (6)]\n" " bond: [mode balance-rr (0) | active-backup (1) | balance-xor (2) | broadcast (3) |\n"
" [primary <ifname>]\n" " 802.3ad (4) | balance-tlb (5) | balance-alb (6)]\n"
" [miimon <num>]\n" " [primary <ifname>]\n"
" [downdelay <num>]\n" " [miimon <num>]\n"
" [updelay <num>]\n" " [downdelay <num>]\n"
" [arp-interval <num>]\n" " [updelay <num>]\n"
" [arp-ip-target <num>]\n\n" " [arp-interval <num>]\n"
" bond-slave: master <master (ifname or connection UUID)>\n\n" " [arp-ip-target <num>]\n\n"
" team: [config <file>|<raw JSON data>]\n\n" " bond-slave: master <master (ifname or connection UUID)>\n\n"
" team-slave: master <master (ifname or connection UUID)>\n" " team: [config <file>|<raw JSON data>]\n\n"
" [config <file>|<raw JSON data>]\n\n" " team-slave: master <master (ifname or connection UUID)>\n"
" bridge: [stp yes|no]\n" " [config <file>|<raw JSON data>]\n\n"
" [priority <num>]\n" " bridge: [stp yes|no]\n"
" [forward-delay <2-30>]\n" " [priority <num>]\n"
" [hello-time <1-10>]\n" " [forward-delay <2-30>]\n"
" [max-age <6-40>]\n" " [hello-time <1-10>]\n"
" [ageing-time <0-1000000>]\n\n" " [max-age <6-40>]\n"
" bridge-slave: master <master (ifname or connection UUID)>\n" " [ageing-time <0-1000000>]\n\n"
" [priority <0-63>]\n" " bridge-slave: master <master (ifname or connection UUID)>\n"
" [path-cost <1-65535>]\n" " [priority <0-63>]\n"
" [hairpin yes|no]\n\n" " [path-cost <1-65535>]\n"
" vpn: vpn-type vpnc|openvpn|pptp|openconnect|openswan\n" " [hairpin yes|no]\n\n"
" [user <username>]\n\n" " vpn: vpn-type vpnc|openvpn|pptp|openconnect|openswan\n"
" olpc-mesh: ssid <SSID>\n" " [user <username>]\n\n"
" [channel <1-13>]\n" " olpc-mesh: ssid <SSID>\n"
" [dhcp-anycast <MAC address>]\n\n" " [channel <1-13>]\n"
" IP_OPTIONS:\n" " [dhcp-anycast <MAC address>]\n\n"
" [ip4 <IPv4 address>] [gw4 <IPv4 gateway>]\n" " IP_OPTIONS:\n"
" [ip6 <IPv6 address>] [gw6 <IPv6 gateway>]\n" " [ip4 <IPv4 address>] [gw4 <IPv4 gateway>]\n"
)); " [ip6 <IPv6 address>] [gw6 <IPv6 gateway>]\n\n"));
} }
static void
usage_connection_modify (void)
{
fprintf (stderr,
_("Usage: nmcli connection modify { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [id | uuid | path] <ID> <setting name>.<property name> [<value>]\n"
"\n"
"Modify a single property in the connection profile.\n"
"The profile is identified by its name, UUID or D-Bus path.\n\n"));
}
static void
usage_connection_edit (void)
{
fprintf (stderr,
_("Usage: nmcli connection edit { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [id | uuid | path] <ID>\n"
"\n"
"Edit an existing connection profile in an interactive editor.\n"
"The profile is identified by its name, UUID or D-Bus path\n"
"\n"
"ARGUMENTS := [type <new connection type>] [con-name <new connection name>]\n"
"\n"
"Add a new connection profile in an interactive editor.\n\n"));
}
static void
usage_connection_delete (void)
{
fprintf (stderr,
_("Usage: nmcli connection delete { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := [id | uuid | path] <ID>\n"
"\n"
"Delete a connection profile.\n"
"The profile is identified by its name, UUID or D-Bus path.\n\n"));
}
static void
usage_connection_reload (void)
{
fprintf (stderr,
_("Usage: nmcli connection reload { help }\n"
"\n"
"Reload all connection files from disk.\n\n"));
}
static void
usage_connection_load (void)
{
fprintf (stderr,
_("Usage: nmcli connection load { ARGUMENTS | help }\n"
"\n"
"ARGUMENTS := <filename> [<filename>...]\n"
"\n"
"Load/reload one or more connection files from disk. Use this after manually\n"
"editing a connection file to ensure that NetworkManager is aware of its latest\n"
"state.\n\n"));
}
/* The real commands that do something - i.e. not 'help', etc. */ /* The real commands that do something - i.e. not 'help', etc. */
static const char *real_con_commands[] = { static const char *real_con_commands[] = {
"show", "show",
@@ -7722,9 +7838,13 @@ parse_cmd (NmCli *nmc, int argc, char **argv)
} else { } else {
if (nmc_arg_is_help (*argv)) { if (nmc_arg_is_help (*argv)) {
usage (); usage ();
nmc->should_wait = FALSE; goto usage_exit;
} }
else if (matches (*argv, "show") == 0) { else if (matches (*argv, "show") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_show ();
goto usage_exit;
}
arg_ret = next_arg (&argc, &argv); arg_ret = next_arg (&argc, &argv);
if (arg_ret != 0 || matches (*argv, "configured") == 0) { if (arg_ret != 0 || matches (*argv, "configured") == 0) {
next_arg (&argc, &argv); next_arg (&argc, &argv);
@@ -7740,19 +7860,31 @@ parse_cmd (NmCli *nmc, int argc, char **argv)
} }
} }
else if (matches(*argv, "up") == 0) { else if (matches(*argv, "up") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_up ();
goto usage_exit;
}
nmc->return_value = do_connection_up (nmc, argc-1, argv+1); nmc->return_value = do_connection_up (nmc, argc-1, argv+1);
} }
else if (matches(*argv, "down") == 0) { else if (matches(*argv, "down") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_down ();
goto usage_exit;
}
nmc->return_value = do_connection_down (nmc, argc-1, argv+1); nmc->return_value = do_connection_down (nmc, argc-1, argv+1);
} }
else if (matches(*argv, "add") == 0) { else if (matches(*argv, "add") == 0) {
if (nmc_arg_is_help (*(argv+1))) { if (nmc_arg_is_help (*(argv+1))) {
usage_connection_add (); usage_connection_add ();
nmc->should_wait = FALSE; goto usage_exit;
} else }
nmc->return_value = do_connection_add (nmc, argc-1, argv+1); nmc->return_value = do_connection_add (nmc, argc-1, argv+1);
} }
else if (matches(*argv, "edit") == 0) { else if (matches(*argv, "edit") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_edit ();
goto usage_exit;
}
editor_thread_data.nmc = nmc; editor_thread_data.nmc = nmc;
editor_thread_data.argc = argc - 1; editor_thread_data.argc = argc - 1;
editor_thread_data.argv = argv + 1; editor_thread_data.argv = argv + 1;
@@ -7760,15 +7892,31 @@ parse_cmd (NmCli *nmc, int argc, char **argv)
g_thread_unref (editor_thread); g_thread_unref (editor_thread);
} }
else if (matches(*argv, "delete") == 0) { else if (matches(*argv, "delete") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_delete ();
goto usage_exit;
}
nmc->return_value = do_connection_delete (nmc, argc-1, argv+1); nmc->return_value = do_connection_delete (nmc, argc-1, argv+1);
} }
else if (matches(*argv, "reload") == 0) { else if (matches(*argv, "reload") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_reload ();
goto usage_exit;
}
nmc->return_value = do_connection_reload (nmc, argc-1, argv+1); nmc->return_value = do_connection_reload (nmc, argc-1, argv+1);
} }
else if (matches(*argv, "load") == 0) { else if (matches(*argv, "load") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_load ();
goto usage_exit;
}
nmc->return_value = do_connection_load (nmc, argc-1, argv+1); nmc->return_value = do_connection_load (nmc, argc-1, argv+1);
} }
else if (matches (*argv, "modify") == 0) { else if (matches (*argv, "modify") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_connection_modify ();
goto usage_exit;
}
nmc->return_value = do_connection_modify (nmc, argc-1, argv+1); nmc->return_value = do_connection_modify (nmc, argc-1, argv+1);
} }
else { else {
@@ -7781,6 +7929,10 @@ parse_cmd (NmCli *nmc, int argc, char **argv)
return nmc->return_value; return nmc->return_value;
usage_exit:
nmc->should_wait = FALSE;
return nmc->return_value;
opt_error: opt_error:
g_string_printf (nmc->return_text, _("Error: %s."), error->message); g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;

View File

@@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 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" #include "config.h"
@@ -273,24 +273,127 @@ usage (void)
fprintf (stderr, fprintf (stderr,
_("Usage: nmcli device { COMMAND | help }\n\n" _("Usage: nmcli device { COMMAND | help }\n\n"
#if WITH_WIMAX #if WITH_WIMAX
" COMMAND := { status | show | connect | disconnect | wifi | wimax }\n\n" "COMMAND := { status | show | connect | disconnect | wifi | wimax }\n\n"
#else #else
" COMMAND := { status | show | connect | disconnect | wifi }\n\n" "COMMAND := { status | show | connect | disconnect | wifi }\n\n"
#endif #endif
" status\n\n" " status\n\n"
" show [<ifname>]\n\n" " show [<ifname>]\n\n"
" connect <ifname>\n\n" " connect <ifname>\n\n"
" disconnect <ifname>\n\n" " disconnect <ifname>\n\n"
" wifi [list [ifname <ifname>] [bssid <BSSID>]]\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" " wifi connect <(B)SSID> [password <password>] [wep-key-type key|phrase] [ifname <ifname>]\n"
" [private yes|no]\n\n" " [bssid <BSSID>] [name <name>] [private yes|no]\n\n"
" wifi rescan [[ifname] <ifname>]\n\n" " wifi rescan [[ifname] <ifname>]\n\n"
#if WITH_WIMAX #if WITH_WIMAX
" wimax [list [ifname <ifname>] [nsp <name>]]\n\n" " wimax [list [ifname <ifname>] [nsp <name>]]\n\n"
#endif #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 */ /* quit main loop */
static void static void
quit (void) quit (void)
@@ -2454,30 +2557,55 @@ do_devices (NmCli *nmc, int argc, char **argv)
if (argc > 0) { if (argc > 0) {
if (nmc_arg_is_help (*argv)) { if (nmc_arg_is_help (*argv)) {
usage (); usage ();
goto usage_exit;
} }
else if (matches (*argv, "status") == 0) { 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)) if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error; goto opt_error;
nmc->return_value = do_devices_status (nmc, argc-1, argv+1); nmc->return_value = do_devices_status (nmc, argc-1, argv+1);
} }
else if (matches (*argv, "show") == 0) { else if (matches (*argv, "show") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_device_show ();
goto usage_exit;
}
if (!nmc->mode_specified) if (!nmc->mode_specified)
nmc->multiline_output = TRUE; /* multiline mode is default for 'device show' */ nmc->multiline_output = TRUE; /* multiline mode is default for 'device show' */
nmc->return_value = do_devices_show (nmc, argc-1, argv+1); nmc->return_value = do_devices_show (nmc, argc-1, argv+1);
} }
else if (matches (*argv, "connect") == 0) { 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); nmc->return_value = do_device_connect (nmc, argc-1, argv+1);
} }
else if (matches (*argv, "disconnect") == 0) { 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); nmc->return_value = do_device_disconnect (nmc, argc-1, argv+1);
} }
else if (matches (*argv, "wifi") == 0) { 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)) if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error; goto opt_error;
nmc->return_value = do_device_wifi (nmc, argc-1, argv+1); nmc->return_value = do_device_wifi (nmc, argc-1, argv+1);
} }
#if WITH_WIMAX #if WITH_WIMAX
else if (matches (*argv, "wimax") == 0) { 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)) if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error))
goto opt_error; goto opt_error;
nmc->return_value = do_device_wimax (nmc, argc-1, argv+1); 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; return nmc->return_value;
opt_error: opt_error:

View File

@@ -14,7 +14,7 @@
* with this program; if not, write to the Free Software Foundation, Inc., * with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * 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" #include "config.h"
@@ -93,12 +93,57 @@ usage_general (void)
{ {
fprintf (stderr, fprintf (stderr,
_("Usage: nmcli general { COMMAND | help }\n\n" _("Usage: nmcli general { COMMAND | help }\n\n"
" COMMAND := { status | hostname | permissions | logging }\n\n" "COMMAND := { status | hostname | permissions | logging }\n\n"
" status\n\n" " status\n\n"
" hostname [<hostname>]\n\n" " hostname [<hostname>]\n\n"
" permissions\n\n" " permissions\n\n"
" logging [level <log level>] [domains <log domains>]\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 static void
@@ -106,11 +151,41 @@ usage_networking (void)
{ {
fprintf (stderr, fprintf (stderr,
_("Usage: nmcli networking { COMMAND | help }\n\n" _("Usage: nmcli networking { COMMAND | help }\n\n"
" COMMAND := { on | off | connectivity }\n\n" "COMMAND := { [ on | off | connectivity ] }\n\n"
" on\n\n" " on\n\n"
" off\n\n" " off\n\n"
" connectivity [check]\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 static void
@@ -119,15 +194,61 @@ usage_radio (void)
fprintf (stderr, fprintf (stderr,
_("Usage: nmcli radio { COMMAND | help }\n\n" _("Usage: nmcli radio { COMMAND | help }\n\n"
#if WITH_WIMAX #if WITH_WIMAX
" COMMAND := { all | wifi | wwan | wimax }\n\n" "COMMAND := { all | wifi | wwan | wimax }\n\n"
" all | wifi | wwan | wimax [ on | off ]\n\n" " all | wifi | wwan | wimax [ on | off ]\n\n"
#else #else
" COMMAND := { all | wifi | wwan }\n\n" "COMMAND := { all | wifi | wwan }\n\n"
" all | wifi | wwan [ on | off ]\n\n" " all | wifi | wwan [ on | off ]\n\n"
#endif #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 */ /* quit main loop */
static void static void
quit (void) quit (void)
@@ -470,6 +591,10 @@ do_general (NmCli *nmc, int argc, char **argv)
usage_general (); usage_general ();
} }
else if (matches (*argv, "status") == 0) { 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)) { if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message); g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; 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) { else if (matches (*argv, "hostname") == 0) {
NMRemoteSettings *rem_settings; NMRemoteSettings *rem_settings;
if (nmc_arg_is_help (*(argv+1))) {
usage_general_hostname ();
goto finish;
}
/* get system settings */ /* get system settings */
if (!(rem_settings = nm_remote_settings_new (NULL))) { if (!(rem_settings = nm_remote_settings_new (NULL))) {
g_string_printf (nmc->return_text, _("Error: Could not get system settings.")); 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) { 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)) { if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) {
g_string_printf (nmc->return_text, _("Error: %s."), error->message); g_string_printf (nmc->return_text, _("Error: %s."), error->message);
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
@@ -515,6 +649,10 @@ do_general (NmCli *nmc, int argc, char **argv)
show_nm_permissions (nmc); show_nm_permissions (nmc);
} }
else if (matches (*argv, "logging") == 0) { else if (matches (*argv, "logging") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_general_logging ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) { if (next_arg (&argc, &argv) != 0) {
/* no arguments -> get logging level and domains */ /* no arguments -> get logging level and domains */
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) { 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)) { if (nmc_arg_is_help (*argv)) {
usage_networking (); usage_networking ();
} else if (matches (*argv, "connectivity") == 0) { } else if (matches (*argv, "connectivity") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_networking_connectivity ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) { if (next_arg (&argc, &argv) != 0) {
/* no arguments -> get current state */ /* no arguments -> get current state */
show_networking_connectivity (nmc); show_networking_connectivity (nmc);
@@ -642,6 +784,13 @@ do_networking (NmCli *nmc, int argc, char **argv)
nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; nmc->return_value = NMC_RESULT_ERROR_USER_INPUT;
} }
} else if (nmc_switch_parse_on_off (nmc, *(argv-1), *argv, &enable_flag)) { } 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 */ nmc->get_client (nmc); /* create NMClient */
nm_client_networking_set_enabled (nmc->client, enable_flag); nm_client_networking_set_enabled (nmc->client, enable_flag);
@@ -652,6 +801,7 @@ do_networking (NmCli *nmc, int argc, char **argv)
} }
} }
finish:
quit (); quit ();
return nmc->return_value; return nmc->return_value;
} }
@@ -680,6 +830,10 @@ do_radio (NmCli *nmc, int argc, char **argv)
usage_radio (); usage_radio ();
} }
else if (matches (*argv, "all") == 0) { else if (matches (*argv, "all") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_all ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) { if (next_arg (&argc, &argv) != 0) {
/* no argument, show all radio switches */ /* no argument, show all radio switches */
if (!nmc_terse_option_check (nmc->print_output, nmc->required_fields, &error)) { 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) { else if (matches (*argv, "wifi") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_wifi ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) { if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WiFi state */ /* no argument, show current WiFi state */
nmc_switch_show (nmc, NMC_FIELDS_NM_WIFI, _("Wi-Fi radio switch")); 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) { else if (matches (*argv, "wwan") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_wwan ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) { if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WWAN (mobile broadband) state */ /* no argument, show current WWAN (mobile broadband) state */
nmc_switch_show (nmc, NMC_FIELDS_NM_WWAN, _("WWAN radio switch")); 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 #if WITH_WIMAX
else if (matches (*argv, "wimax") == 0) { else if (matches (*argv, "wimax") == 0) {
if (nmc_arg_is_help (*(argv+1))) {
usage_radio_wimax ();
goto finish;
}
if (next_arg (&argc, &argv) != 0) { if (next_arg (&argc, &argv) != 0) {
/* no argument, show current WiMAX state */ /* no argument, show current WiMAX state */
nmc_switch_show (nmc, NMC_FIELDS_NM_WIMAX, _("WiMAX radio switch")); nmc_switch_show (nmc, NMC_FIELDS_NM_WIMAX, _("WiMAX radio switch"));