Commit Graph

187 Commits

Author SHA1 Message Date
Beniamino Galvani
c955d91d4b cli: remove assertion in nmc_device_state_to_color()
nmcli should not fail when the state device state is > ACTIVATED.
Just return an unknown color code like we used to do, and like we do
for connections.

Fixes: 31aa2cfe29

https://bugzilla.gnome.org/show_bug.cgi?id=796834
2018-08-10 10:10:51 +02:00
Thomas Haller
ac07cbb98b cli: minor cleanup explicitly checking print_output
The print-output knows three modes: NORMAL, PRETTY, TERSE.
Never compare whether a mode is != a particular mode.

Instead, always explicitly check for the modes for which we enable a
particular behavior.

The effect is, that we always do something when the mode is set to a
particular value. We don't ever do something, if the mode is not set to
a particular value. Consistently opt-in is easier to understand.
2018-07-25 17:08:37 +02:00
Thomas Haller
e0570ae8d6 cli: don't translate device state in --terse mode 2018-07-25 17:08:37 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
d7b643f66f cli/trivial: move code 2018-07-09 15:43:55 +02:00
Thomas Haller
ba350a3495 cli: add additional user-data argument to get_fcn()
The function nmc_print() receives a list of "targets". These are essentially
the rows that should be printed (while the "fields" list represents the columns).

When filling the cells with values, it calles repeatedly get_fcn() on the
column descriptors (fields), by passing each row (target).

The caller must be well aware that the fields and targets are
compatible. For example, in some cases the targets are NMDevice
instances and the target type must correspond to what get_fcn()
expects.

Add another user-data pointer that is passed on along with the
targets. That is useful, if we have a list of targets/rows, but
pass in additional data that applies to all rows alike.

It is still unused.
2018-07-09 15:43:55 +02:00
Thomas Haller
918be83493 cli: rework printing of "wired" and "wifi" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
d6949a2924 cli: rework printing of "capabilities" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
2fc475ccdf cli: rework printing of "connections" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
e771153c0a cli: don't translate device details in terse mode
https://bugzilla.gnome.org/show_bug.cgi?id=794329
2018-07-09 15:43:55 +02:00
Thomas Haller
6f8f7ad597 cli: rework enum-to-string function to not return translated text
There are cases, where we need the untranslated text.

There is no change of behavior of this patch, because all
callers now explicitly call gettext().
2018-07-09 15:43:55 +02:00
Thomas Haller
fede017001 cli: rework printing of "general" device details 2018-07-09 15:43:55 +02:00
Thomas Haller
283b1d18b7 cli: rework printing of device status 2018-07-09 15:43:55 +02:00
Thomas Haller
940979a5a6 cli: merge IPv4 and IPv6 versions of ip/dhcp config print 2018-07-09 15:43:55 +02:00
Thomas Haller
ff273b8221 cli: drop duplicate IPv6 property metadata 2018-07-09 15:43:55 +02:00
Thomas Haller
096ac93f8a cli: rework printing of dhcp options 2018-07-09 15:43:55 +02:00
Thomas Haller
efddb0cef5 tests: improve NetworkManager stub service for Wi-Fi scanning
Now that nmcli initiates a scan before displaying Wi-Fi networks,
the stub service must properly support that as well.

For the moment, the stub service chooses "now" as LastScan timestamp.
This causes nmcli not to trigger a new scan, because nmcli gives
unstable output if multiple nmcli processes in parallel race to
trigger a Wi-Fi scan. That should be fixed.

(cherry picked from commit 56a0488bba)
2018-06-18 10:58:05 +02:00
Lubomir Rintel
5269aba7b4 cli: utilize nm_utils_get_timestamp_msec() 2018-06-15 16:23:30 +02:00
Lubomir Rintel
07fd0502f6 wifi: expose LastScan as milliseconds not seconds
This doesn't wrap around in 68 years of uptime and is consistent with
o.fd.NM.Checkpoint.Created.
2018-06-15 16:23:30 +02:00
Andrew Zaborowski
140ada3aad cli: Actually add passwords to the AddAndActivateConnection arguments
Check the wpa_flags and rsn_flags values to see if the network needs the
password added to the 802-11-wireless-security settings.  The current
ap_flags check alone would only trigger the password to be sent for WEP
networks.  Also remove unneeded initialization of the three variables.
2018-06-13 15:59:48 +02:00
Lubomir Rintel
34412a8d3d cli/devices: rescan the Wi-Fi network if the AP list is not fresh enough 2018-06-13 14:48:23 +02:00
Lubomir Rintel
ca29761212 cli/devices: parse "nmcli d wifi list" arguments with next_arg()
For no reason at all.
2018-06-13 14:44:42 +02:00
Andrew Zaborowski
e8a197506c client: cli: Fix message in connect callback
https://github.com/NetworkManager/NetworkManager/pull/134
2018-06-12 08:09:48 +02:00
Lubomir Rintel
31aa2cfe29 cli: use a palette to implement coloring
This basically replaces the (NMMetaTermColor, NMMetaTermFormat) combo
with NMMetaColor that describes the colored element semantically as
opposed to storing the raw attributes.

A (currently static) paletted is used to translate the semantic color
code to the actual ANSI controle sequence. This matches what
terminal-colors.d(5) schemes use, making it convenient to implement
customizable palettes.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
9dfe825840 cli: rework enabling and disabling colors
This actually makes very little difference at the moment, but will make
things more confortable later on, when the logic of enabling/disabling
coloring will involve terminal-colors.d(5).

Instead of deciding whether to use colors lazily with use_colors(), it's
done very early on nmcli initialization and a boolean use_colors field
is stored in the NmcConfig instance instead of the raw tristate option
of NmcColorOption type (which is now confined to nmcli.c).

Wherever the NmcColorOption was used previously, the whole NmcConfig
instance is passed around. That might seem pointless (since only the
use_colors boolean is actually used at the moment), but will be utilized
to pass around the actual color palette in future.
2018-05-10 14:36:58 +02:00
Lubomir Rintel
e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Thomas Haller
5e69b8b9f1 cli: merge IPv4 and IPv6 variants of print_dhcp_config() 2018-04-23 15:43:39 +02:00
Lubomir Rintel
9e4de97967 libnm-core: move detection of UTF-8 capable terminals to clients/
Having it in libnm doesn't make any sense and prevents using it for more
internal functionality.

Too bad nm_utils_wifi_strength_bars() is already a public API.
No problem -- replace it with a compatible yet dumber equivalent.
2017-12-18 14:47:37 +01:00
Thomas Haller
c274b565a6 cli: avoid out-of-bounds-read for show_device_info()
Probably not critical, because it will still include
the terminating NULL, and just continue to fill the
temporary buffer with static addresses.

Found by coverity.

Fixes: bfb9fd0d2f
2017-12-12 11:15:38 +01:00
Thomas Haller
2e974baa15 cli: use nm_clear_g_source() util in quit() functions 2017-11-29 10:19:12 +01:00
Beniamino Galvani
7af471919a cli: wifi: connect with PSK when the AP supports WPA-PSK and WPA-EAP
'nmcli device wifi connect' only supports WEP and WPA-PSK at the
moment, but not WPA-EAP. If the AP supports both WPA-PSK and WPA-EAP,
nmcli doesn't add the PSK to the connection, causing a connection
failure. Fix this.

https://bugzilla.redhat.com/show_bug.cgi?id=1492064
2017-09-20 09:23:54 +02:00
Lubomir Rintel
d473b34745 cli: prioritize devices with default routes and addresses
This makes "nmcli" and "nmcli d" output slightly more useful.
2017-06-26 15:17:49 +02:00
Beniamino Galvani
d2b4332b36 cli: remove spurious device names from output
When running one of:

 nmcli device wifi list ifname wlan0
 nmcli device wifi connect ... ifname wlan0

nmcli wrongly adds the device name to the output.

Do the completion only when requested.

Fixes: 8679793f6b
Fixes: 1a0dfd31c4
2017-06-11 22:31:43 +02:00
Beniamino Galvani
f13fd4524c all: detect SR-IOV device support 2017-04-18 22:48:34 +02:00
Thomas Haller
41b31051f2 cli: use nmc_print() to output device's IP4 info
The IP4 info adds a new type: to expose strv arguments
for addresses, etc.
2017-04-12 14:00:00 +02:00
Thomas Haller
c5c48d4f5f cli: move global "loop" variable to nmcli.h header 2017-04-12 11:24:04 +02:00
Thomas Haller
f0d91455ca cli: move show_secret field to NmcConfig
The show-secret property is basically a part of the current
configuration, relevant during printing. It will be passed
on to nmc_print(), and hence must be part of NmcConfig.
2017-04-12 11:24:04 +02:00
Francesco Giudici
2c4e991aba nmcli: fix "nmcli device monitor <dev>"
Call get_device_list() after next_arg(); call it only after checking
that there are other arguments after "monitor".

Fixes: 6a3d77fbe6
2017-04-11 15:49:30 +02:00
Thomas Haller
ca0e749c40 cli: move and rename TermColor and TermFormat 2017-04-05 16:53:06 +02:00
Thomas Haller
9276655975 cli: move NmcMetaGenericInfo to "utils.h" 2017-04-05 16:53:06 +02:00
Thomas Haller
bfb9fd0d2f cli: split tracking of meta data out of NmcOutputField
When generating output data, nmcli iterates over a list of
property-descriptors (nmc_fields_ip4_config), creates an intermediate
array (output_data) and finally prints it.

However, previously both the meta data (nmc_fields_ip4_config) and
the intermediate format use the same type NmcOutputField. This means,
certain fields are relevant to describe a property, and other fields
are output/formatting fields.

Split this up. Now, the meta data is tracked in form of an NMMetaAbstractInfo
lists. This separates the information about properties from intermediate steps
during creation of the output.

Note that currently functions like print_ip4_config() still have all the
knowledge about how to generate the output. That is wrong, instead, the
meta data (NMMetaAbstractInfo) should describe how to create the output
and then all those functions could be replaced. This means, later we want
to add more knowledge to the NMMetaAbstractInfo, so it is important to
keep them separate from NmcOutputField.
2017-04-05 16:53:06 +02:00
Thomas Haller
aae721d0df cli: pass arguments for print_data separately of NmcOutputData
Don't pass on large structs of input arguments. It only convolutes
which arguments are passed, and where they come from.
2017-04-05 16:53:06 +02:00
Thomas Haller
f973f0841a cli: merge NmcPrintFields into NmcOutputData and pass it directly to print_required_fields() 2017-04-05 16:53:06 +02:00
Thomas Haller
ea700eec84 cli: tighter scope NmcOutputData in do_device_wifi_list()
The scope of "out" can be reduced.
2017-04-05 16:53:06 +02:00
Thomas Haller
f12106d83a cli: use enum NmcOfFlags instead of plain integer flags and pass to print_required_fields() 2017-04-05 16:53:06 +02:00
Francesco Giudici
6a3d77fbe6 nmcli: allow cmd specific option parsing in next_arg() func
Options dependant on specific commands (e.g., nmcli connection show
--active) are now allowed to be processed by the next_arg() function.
This would allow autocompletion to expand options belonging to specific
command first, and then global ones.

Note that global options ("--ask" and "--show-secrets") will be auto-completed
everywhere but only if at least a '-' is passed. Command specific ones
(--temporary, --active, --order) will be auto-completed only after the command
they belongs to but without requiring the user to pass a heading '-'.

Example:
'nmcli connection show -a'
will expand '-a' into '--active', but
'nmcli connection add -a`
will expand '-a' into '--ask' (as it is a global option)

This commit fixes also autocompletion for:
nmcli connection modify --temporary
2017-04-05 15:43:40 +02:00
Beniamino Galvani
db07b867a6 cli: restore previous name of IN-USE AP property
Before commit a63c4d0824 ("cli: use designated initializers for
setting NmcOutputField fields") each field had a @name and a
@name_l10n , which were equal for all properties except for wifi
IN-USE:

 {"IN-USE",     N_("*")},          /* 15 */

The commit removed @name_l10n so now the displayed name is equal to
the field name. But now:

 $ nmcli device wifi list
 Error: 'device wifi': invalid field 'IN-USE'; allowed fields:
 NAME,SSID,SSID-HEX,BSSID,MODE,CHAN,FREQ,RATE,SIGNAL,BARS,SECURITY,
 WPA-FLAGS,RSN-FLAGS,DEVICE,ACTIVE,*,DBUS-PATH

The new field name should be 'IN-USE' and not '*', otherwise scripts
doing "-f IN-USE" will break. As a side effect we now show 'IN-USE'
instead of '*' in the column header, which seems easier to understand:

IN-USE  SSID     MODE   CHAN  RATE       SIGNAL  BARS  SECURITY
*       default  Infra  5     54 Mbit/s  71      ▂▄▆_  WPA2
        guest    Infra  1     54 Mbit/s  62      ▂▄▆_  WPA2

Fixes: a63c4d0824
2017-04-01 21:33:11 +02:00
Thomas Haller
29bcfc2522 cli: don't track output data in global NmCli structure
We should not violate the global data to track the output data
while it is constructed and printed.

Most of the time, we actually clear the output data anyway --
either before constructing it, or after printing it.
In some cases we didn't, but I think that is a bug. It's really
hard to keep track of this.

The output data should belong to a certain scope and get destroyed
afterwards. Passing it around is very confusing. Don't do that.
2017-03-30 14:56:21 +02:00
Thomas Haller
85acdd70e7 cli: split print_data() in a part with and without side-effects
To better understand which part of the code have side effects,
split print_data() in a part that mutilates the input array
and a part that only prints.
2017-03-30 13:46:09 +02:00