Commit Graph

48 Commits

Author SHA1 Message Date
Thomas Haller
582ee91145 cli: add functionality to hide properties from output
Historically, nmcli printed all fields during operations like
`nmcli connection show "$PROFILE"`. As we supported more and
more options, this resulted in a verbose output, of most properties
just being the default values.

To counter that, we added the '-overview' option. When given,
it would hide options that are set at their default. This option
was not the default, to preserve established behavior.

However, for new options, we can afford to hide them. Add a mechanism,
that property getters can mark their value to be hidden. At the moment,
there is no way to show these properties. However, we could add a
'-verbose' option, with the opposite meaning of '-overview'. Anyway,
that does not seem necessary at the moment.

Hiding properties from output is only acceptable for new properties
(otherwise we badly change behavior), and if the properties are set
at their default values (otherwise, we hide important information).
2018-08-10 10:38:19 +02:00
Thomas Haller
df30651b89 libnm, cli, ifcfg-rh: add NMSettingEthtool setting
Note that in NetworkManager API (D-Bus, libnm, and nmcli),
the features are called "feature-xyz". The "feature-" prefix
is used, because NMSettingEthtool possibly will gain support
for options that are not only -K|--offload|--features, for
example -C|--coalesce.

The "xzy" suffix is either how ethtool utility calls the feature
("tso", "rx"). Or, if ethtool utility specifies no alias for that
feature, it's the name from kernel's ETH_SS_FEATURES ("tx-tcp6-segmentation").
If possible, we prefer ethtool utility's naming.

Also note, how the features "feature-sg", "feature-tso", and
"feature-tx" actually refer to multiple underlying kernel features
at once. This too follows what ethtool utility does.

The functionality is not yet implemented server-side.
2018-08-10 10:38:19 +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
Lubomir Rintel
5da77c0e2c client: support wpan setting 2018-06-26 16:21:55 +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
Beniamino Galvani
aca671fff0 all: replace "it's" with "its" where needed 2018-04-18 14:14:07 +02:00
Beniamino Galvani
1f2319dcb9 clients: change nm_meta_abstract_info_get() to report defaults
Return a boolean to indicate whether the value is the default one, so
that the caller can choose to hide it.
2018-04-13 17:02:55 +02:00
Beniamino Galvani
8b4bb725d7 clients: meta: add enum getter-only nicks
Add a new a new field to enum type descriptors that specify a list of
nicks valid only for getter functions. It is useful when the get
function must return a string different from the enum nick and that
string can't be used to set a value.
2018-04-13 17:02:55 +02:00
Thomas Haller
343c967e66 clients: make meta data subtypes of NMObjBaseInst
Yes, this wastes 4 times an unused GType instance
in the class structure.
2017-07-05 14:22:10 +02:00
Beniamino Galvani
46d2168393 clients: reorder properties of connection setting
The order matters for the 'nmcli connection show' output and for the
interactive mode of nmcli. Users should not rely on the order in both
cases, but since we have an extensive test suite for the interactive
mode, restore the order as it was in 1.8.
2017-06-22 15:01:15 +02:00
Lubomir Rintel
aedeb3cbf4 clients: add support for Bluetooth NAP type 2017-05-31 20:17:42 +02:00
Thomas Haller
c72a07a604 clients: implement wifi-sec.wep-key-type as enum property
This way, we get tab completion for the enum values, and
can reuse existing code.

This requires a pre-set-notify hook, that is invoked before
setting the property.
2017-05-23 13:37:10 +02:00
Thomas Haller
e086cf1887 clients: add value_infos for int getter
This allows to implement a pretty alias for numbers,
like "default" for 0.
2017-05-23 13:37:10 +02:00
Thomas Haller
b6d9bdcee8 clients: combine int property setters
Instead of having 3 implementations for setting an int (int, uint, int64), combine
them. Also, make them more configurable by allowing to specify min/max/base, outside
of GParamSpec.
2017-05-23 13:37:10 +02:00
Thomas Haller
35d6802724 clients: add validate_fcn for string property 2017-05-23 13:37:10 +02:00
Thomas Haller
83a6f36207 cli: don't mark field names for translation
Before refactoring nmcli recently, field names were marked for translation.
Note that for the property names, marking them had no effect as only
plain strings can be marked with N_().

Note how --fields are also an input argument. The input should be
independent of the locale and not translated. Likewise, when printing
the header names, they should not be translated to match the --fields
option.

    $ LANG=de_DE.utf8 nmcli --fields GENERAL.DEVICE device show enp0s25
    GENERAL.GERÄT:                          enp0s25

Drop the translation marks.
2017-04-23 23:45:02 +02:00
Thomas Haller
9fcbe4ff71 cli: don't use #define for translation texts
Text for translation cannot contain defines (or variables).
2017-04-23 23:45:02 +02:00
Thomas Haller
275ab5fb8f cli: make properties list a list of pointers
That allows for the property list to contain derived
property types. Also, the list can be directly passed
off as a "const NMMetaAbstractInfo *const*" list.
2017-04-13 10:10:12 +02:00
Thomas Haller
f2b5a42c7c cli: let NMMetaNestedPropertyInfo derive NMMetaPropertyInfo 2017-04-13 10:10:12 +02:00
Thomas Haller
6d12d2f3a0 cli: move setting creation to meta data 2017-04-12 14:12:20 +02:00
Thomas Haller
b629b98687 cli: move completion for connection type to meta data 2017-04-12 14:12:20 +02:00
Thomas Haller
2a760897f2 cli: move completion for master connections to meta data
This change (improves) behavior.

Before, we would only complete
  if (g_strcmp0 (con_type, nmc_tab_completion.con_type) != 0)
which doesn't really make sense as it depends on the slave-type,
not nmc_tab_completion.con_type.
2017-04-12 14:12:20 +02:00
Thomas Haller
1e4bc51a4a cli: move completion for devices names to meta data 2017-04-12 14:12:20 +02:00
Thomas Haller
d32817999c cli: move information about valid connection settings to common 2017-04-12 14:12:20 +02:00
Thomas Haller
3ed0fc1b45 cli: move setting alias to meta data 2017-04-12 14:12:20 +02:00
Thomas Haller
0fa5fc3f51 cli: move completing VPN service types to meta data 2017-04-12 14:12:19 +02:00
Thomas Haller
cfd9f66ae9 cli: add property completion to meta-data
(not used yet).
2017-04-12 14:12:19 +02:00
Thomas Haller
4f19c46a1e cli: move part of setting meta data from "connection.c"'s OptionInfo 2017-04-12 14:12:19 +02:00
Thomas Haller
6763097cc9 cli: make OptionInfo immutable
Don't mutate global state. For now, hack around it by putting
the mutable flags to a separate (global) cache. Obviously, it
still uses global data, but it no longer touches the global
option_info list.
2017-04-12 14:12:06 +02:00
Thomas Haller
e5ebf7a7ef cli: move property option flags to nm-meta-settings-desc.h 2017-04-12 14:10:57 +02:00
Thomas Haller
ddfff04a45 cli: extend NMMetaSettingInfoEditor's get_fcn() to support different output forms 2017-04-12 14:10:56 +02:00
Thomas Haller
b7efa62745 cli: cleanup meta data virtual function arguments
- have the "self" argument first, before the environment arguments.
  It's more idiomatic.
- from within cli, always pass nmc_meta_environment and nmc_meta_arg
  where needed.
- drop the union in NMMetaAbstractInfo. I was suppost to make casts
  nicer, but it doesn't really.
2017-04-12 14:00:00 +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
3045daf127 cli: use nmc_print() to output setting data 2017-04-12 11:24:04 +02:00
Thomas Haller
fdd40b6a68 cli: implement new nmc_print() command to generically output cli data
We already have
  - data sources (nm_cli, connections or settings)
  - meta data information how to access the data sources (NMMetaAbstractInfo,
    NmcMetaGenericInfo, NMMetaPropertyInfo)

Add now a generic way to output cli data using nmc_print(). It gets a
list of data-sources (@targets) and a list of available fields (meta
data). It also gets cli configuration (NmcConfig) and field selector
strings (@field_str).

Based on that, it should output the desired data.

This is intended to replaces the previous approach, where functions like
show_nm_status() have full knowledge about how to access the data and
create an intermediate output format (NmcOutputData, NmcOutputField)
that was printed via print_data().
show_nm_status() contained both knowledge about the data itself (how to
print a value) and intimate knoweledge about the output intermediate
format. Also, the intermediate format is hard to understand. For
example, sometimes we put the field prefix in NmcOutputField at index 0
and via the NmcOfFlags we control how to output the data.

Clearly separate the responsibilities.

  - The meta data (NmcMetaGenericInfo) is only concerned with converting
    a data source to a string (or a color format).
  - the field selection (@field_str) only cares about parsing the list
    of NMMetaAbstractInfo.
  - _print_fill() populates a table with output values and header
    entries.
  - _print_do() prints the previously prepared table.

The advantage is that if you want to change anything, you only need to
touch a particular part.

This is only a show-case for `nmcli general status`. Parts are still
un-implemented and will follow.

This changes behavior for --terse mode: the values are now no longer
translated:
  $ LANG=de_DE.utf8 nmcli -t --mode multiline general
2017-04-12 11:24:04 +02:00
Thomas Haller
ca0e749c40 cli: move and rename TermColor and TermFormat 2017-04-05 16:53:06 +02:00
Thomas Haller
e3a07633dc cli: fix signature of NMMetaAbstractType:get_fcn()
Depending on the get_type argument, we don't only want
to return strings, but arbitrary pointers.

The out_to_free argument still makes sense, but depending on
the get-type you must know how to free the pointer.
2017-04-05 16:53:06 +02:00
Thomas Haller
bb40abb3de cli: move nmc_bond_validate_mode() to "clients/common/nm-client-utils.h"
"clients/common/nm-client-utils.h" already contains other nmc_* validation functions.
It's the better place for nmc_bond_validate_mode()
2017-04-05 16:53:06 +02:00
Thomas Haller
19c70ace95 cli: add get_fcn() to NMMetaAbstractInfo 2017-04-05 16:53:06 +02:00
Thomas Haller
137273669d cli: add nmc_output_selection_create() to parse field selection
nmc_output_selection_create() returns a less opaque result then
a GArray and a GPtrArray for the groups.
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
6a489199b9 cli: make setting meta data more generic
Embed a @meta_type structure in NMMetaSettingInfoEditor and
NMMetaPropertyInfo. This allows to make the NMMeta*Info instances
themself to become generic and they can be passed around as generic
NMMetaAbstractInfo types.
For one, the embedded NMMetaType pointer can be used to determine
of which type a NMMetaAbstractInfo instance is. On the other hand,
the NMMetaType struct can be extended to be a VTable to provide
generic access to the type.
In the end, both NMMetaSettingInfoEditor and NMMetaPropertyInfo are
conceptionally very similar: the describe a certain type and provide
accessors.

In nmcli we have yet another NMMetaAbstractInfo type: NmcOutputField
will be modified to become another implementation of meta data (it
already is, it just cannot be used interchangable with the other
types).

Also, embed the NMMetaSettingInfoEditor in the NMMetaPropertyInfo
instance. This allows from a given NMMetaPropertyInfo to retrieve it's
parent NMMetaSettingInfoEditor.
2017-04-05 16:53:06 +02:00
Thomas Haller
2379af7e36 cli: notify warning via NMMetaEnvironment instead of printing directly from "nm-meta-setting-desc.h"
The lower layers are concerned with handling settings. They should not
be aware of how to notify about warnings. Instead, signal them via
the warn_fcn() hook.
2017-04-05 16:53:06 +02:00
Thomas Haller
d720f0955f cli: embed gtk-doc directly in property-info structure
Also mark them for translation.
2017-03-30 16:35:52 +02:00
Thomas Haller
f5a0b62765 cli: use enum property type for connection.lldp
Change in behavior:

  - the setter would previoulsy allow "enable" case-insensitive.
    Now, it's case sensitive.
2017-03-30 13:09:58 +02:00
Thomas Haller
f53218ed7c cli: add property type for enum and showcase for ipv6.addr-gen-mode 2017-03-30 13:09:58 +02:00
Thomas Haller
23298bfc88 cli: move utils function from common.h to nm-meta-setting-desc.c
These functions are only used by nm-meta-setting-desc.c. Make them internal.
Unfortunately, they are part of "common.h" which cannot be used without
the rest of nmcli. Still todo.
2017-03-30 13:09:58 +02:00
Thomas Haller
b5c8622ad3 cli: split nm-meta-setting-desc out of settings
This part contains static functions and variables to describe
settings. It is distinct from the mechanism to use them, or
access them.

Split it out.

It still uses clients/cli/common.h and clients/cli/utils.h
which shall be fixed next.
2017-03-30 13:09:58 +02:00