Commit Graph

206 Commits

Author SHA1 Message Date
Beniamino Galvani
6a51d393b2 shared: add @allow_escaping argument to @nm_utils_strsplit_set 2018-08-11 09:41:07 +02:00
Thomas Haller
d70dcb16da cli: fix nmc_setting_get_valid_properties() to use setting metadata
Not all properties that we want to handle in nmcli are actual GObject
properties. For the moment that was the case, but that's about to change.

This is a change in behavior with respect of the order in which
properties are reported. For example, print_setting_description()
now prints the property descriptions in a different order. However,
one might argue that this order makes more sense because:

  - it's the same order as properties are listed in
    "nm-meta-setting-desc.c". At that place, we have explict
    control over the order and set it intentionally to suite
    our needs best. The order of the GObject properties is
    much less well defined.

  - the order from "nm-meta-setting-desc.c" is used at several other
    places. So, it makes sense to use the same order everywhere.
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
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
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
Thomas Haller
5d3736ac65 cli: drop nmc_strsplit_set()
In most cases, it copies the entire strv needlessly.
We can do better.

Also, the max_tokens argument is handled wrongly (albeit
not used anywhere anymore).
2017-12-12 15:19:43 +01:00
Beniamino Galvani
5e239d2c04 cli: don't print warnings when completing arguments
$ nmcli con add type wifi ifname wlan0 \
     wifi-sec.key-mgmt none \
     wifi-sec.wep-key0 $ascii_key \
     ssid <TAB>

 completes the line with:

  "Info:\ WEP\ key\ is\ guessed\ to\ be\ of\ '2\ \(passphrase\)'"

The environment warning function should not emit warning when
completing arguments.
2017-12-01 14:27:38 +01: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
6d12d2f3a0 cli: move setting creation 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
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
3045daf127 cli: use nmc_print() to output setting data 2017-04-12 11:24:04 +02:00
Beniamino Galvani
c9c029181e cli: do not show description of unsupported properties
Properties without meta data cannot be set or displayed: do
not show them.
2017-04-12 10:18:01 +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
db300afba1 cli: split out new file "nm-meta-setting-access.h"
"nm-meta-setting-desc.h" contains static type description, vtable and (internal)
accessor functions. Add accessor functions that operate on top of the type description
to "nm-meta-setting-access.h".
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
cecee19b2b cli: move pre-check for setting connection:secondaries out of nm-meta-setting-desc.c
This check requires additional information about the environment, that
is about the present connections in NMClient.

"nm-meta-setting-desc.c" should be independent from the libnm D-Bus
cache, hence move this code to "settings.c".
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
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
Thomas Haller
2ea670ab96 cli: split output data from NmCli to a separate field 2017-03-30 13:34:35 +02:00
Thomas Haller
98ce4a8d5d cli: separate input and in-out arguments in print_data()
Don't pass down the entire NmCli instance. The output_data
array is modified by print_data(), the rest is read-only input.
2017-03-30 13:09:59 +02:00
Thomas Haller
e847d0f121 cli: pass configuration options separately from NmCli structure
The NmCli structure is passed around everywhere and contains all
the state of the program. It is very hard to follow which parts
are used where.

Split out more configuration options to a NmcConfig field. This field
is mostly immutable, and modified at particular places that now can be
easily found.
2017-03-30 13:09:59 +02:00
Thomas Haller
a63c4d0824 cli: use designated initializers for setting NmcOutputField fields
Otherwise, changing the structure is difficult because it all depends
on the order (and you don't immdiately see which field is used where).

Also, drop the name_l10n field.
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
Thomas Haller
2a71b5322f cli/trivial: rename metadata related names
They will be moved out of nmcli as they are generally useful.
Even if they happen to be used only inside nmcli, there should
be a better separation between logic (nmcli) and setting decriptions.
2017-03-30 13:09:57 +02:00
Thomas Haller
fcc19ea760 nmcli: output property values in "parsable" mode when the "--terse" option is specified (again)
Commit 623d888801 was reverted during
refactoring nmcli to simplify merge conflicts. Restore the behavior
of the patch.
2017-03-30 13:09:57 +02:00
Thomas Haller
660fee1622 cli: allow dynamic results from values_fcn() and describe_fcn() property functions
Mostly these strings are static. In same cases they are generated
however. Instead of caching them in a static variable, return them
to the caller.

And belatedly fix invoking describe_fcn().
2017-03-30 13:09:57 +02:00
Thomas Haller
8e74837f14 cli: refactor indirection to legacy signatures (2) 2017-03-30 13:09:57 +02:00
Thomas Haller
24434be5a1 cli: fix intermediate regression of hiding blobs data
Restore previous behavior of hiding blobs for certain
certificate properties.
2017-03-30 13:09:57 +02:00
Thomas Haller
d92b50fc70 cli: use define for argument lists in settings.c
settings.c basically consists of property-type structures and *a lot* of
accessors. All these accessors share the same argument list.

It is very repetitive to specify it over and over again. Also, there
are so many arguments that one is compelled to wrap the lines. All
in all it results in a lot of noise that takes the eye from the important
code.

Also, the argument list is expected to change, so we possibly only
have to change one place.
2017-03-30 13:09:57 +02:00
Thomas Haller
4bfb3c8aa7 cli: refactor indirection to legacy signatures 2017-03-30 13:09:57 +02:00
Thomas Haller
e1d60712d9 cli: add property-info for the rest 2017-03-30 13:09:57 +02:00
Thomas Haller
10fca1ae3a cli: add property-info for NMSettingWireless 2017-03-30 13:09:57 +02:00
Thomas Haller
84aa6bad89 cli: add property-info for NMSettingWired 2017-03-30 13:09:57 +02:00
Thomas Haller
486dc1e596 cli: add property-info for NMSettingWimax 2017-03-30 13:09:57 +02:00
Thomas Haller
d07acc753c cli: let string property-type handle checking values 2017-03-30 13:09:56 +02:00
Thomas Haller
9c6f70f9e0 cli: add property-info for NMSettingAdsl 2017-03-30 13:09:56 +02:00
Thomas Haller
f34ef5d1fe cli: add property-info for NMSettingPpp 2017-03-30 13:09:56 +02:00
Thomas Haller
6bf1d6fc16 cli: add property-info for NMSetting8021x 2017-03-30 13:09:56 +02:00
Thomas Haller
d530bffb6c cli: add property-info for NMSettingWirelessSecurity 2017-03-30 13:09:56 +02:00
Thomas Haller
09d127b473 cli: add property-info for NMSettingPppoe 2017-03-30 13:09:56 +02:00