Commit Graph

123 Commits

Author SHA1 Message Date
Thomas Haller
24a732c8e7 cli: show new enable-disable-connectivity-check permission 2017-08-17 23:09:07 +02:00
Beniamino Galvani
65a0208ba0 core,cli: replace wrong pattern for clearing GError
Use gs_free_error instead of gs_free.
2017-06-27 09:42:28 +02:00
Thomas Haller
ee5fdcbfb5 cli: minor refactoring of if-condition in device_overview
Note that nm_device_get_ip_iface() never returns an emptry string "".
2017-06-09 15:34:31 +02:00
Thomas Haller
126b0874f1 cli: fix output of iface in overview output
Fixes: f14845cc20

https://bugzilla.redhat.com/show_bug.cgi?id=1460219
2017-06-09 15:34:31 +02:00
Lubomir Rintel
24c079e4b2 cli: spawn a pager when running on a terminal
This makes it a lot more convenient to deal with long outputs (such as
"nmcli c show id ...").

The implementation is essentially jacked from systemd. The bugs are
mine.
2017-05-15 17:23:51 +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
03307e3dd6 cli: use nmc_print() to output nmcli general logging 2017-04-12 11:24:04 +02:00
Thomas Haller
16299e5ac0 cli: use nmc_print() to output nmcli general permissions
Add also colors for the output values.
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
e79174ca89 cli: refactor enum-to-string function to have non-translating version
We need both translated and non-translated versions.
2017-04-12 11:24:04 +02:00
Thomas Haller
ce28918dbf cli/trivial: move code 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
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
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
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
9359d5622e cli: pass use_colors as separate option instead of global nmc
nmc contains all options and collects output data. It is very hard to
understand what it does. Start splitting it up, and pass arguments along
-- as needed.
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
Francesco Giudici
ef0d0d08eb nmcli: fix nmcli parsing
Fixes the parsing for correct and incorrect commands.
e.g.:
nmcli connection down id <conn>
nmcli -t
...

Fixes: 16902a2be6
2017-03-29 13:02:39 +02:00
Lubomir Rintel
5a71bc8022 cli: add NmCli argument to next_arg()
Will be useful in next commit.
2017-03-28 15:32:05 +02:00
Lubomir Rintel
16902a2be6 cli: use next_arg() on argument boundary
Shift argc and argc manually between argument ant its value and use
next_arg() between arguments everywhere. Whill be useful to parse global
arguments.
2017-03-28 15:32:05 +02:00
Francesco Giudici
7d96f1f17d nmcli: don't enforce anymore the -f(ields) option in -t(erse) mode 2017-03-28 10:55:00 +02:00
Lubomir Rintel
81cd300108 cli/general: avoid chopping off the last letter of master device name
...when "nmcli" is called without argument and the master device is the last
entry printed.
2017-03-16 17:11:58 +01:00
Lubomir Rintel
84c484ed5b cli: make match() return boolean
Coccinelle semantic patch:

  @@
  @@
  -int
  +gboolean
          matches (...);

  @@
  expression pattern, cmd, len;
  @@
  -int
  +gboolean
          matches (...)
          {
                  ...
  -               return memcmp (pattern, cmd, len);
  +               return memcmp (pattern, cmd, len) == 0;
          }

  @@
  expression prefix, str;
  @@
  (
  -matches (prefix, str) != 0
  +!matches (prefix, str)
  |
  -matches (prefix, str) == 0
  +matches (prefix, str)
  )

  @@
  expression prefix, str;
  @@
  -(matches (prefix, str))
  +matches (prefix, str)

  @@
  expression prefix, str;
  @@
  -(!matches (prefix, str))
  +!matches (prefix, str)

spatch --smpl-spacing --sp-file match.cocci --dir clients/cli/ \
  --include-headers --macro-file shared/nm-utils/gsystem-local-alloc.h
2017-02-15 13:04:07 +01:00
Lubomir Rintel
1d40c5f476 cli: add nmcli g logging completion
This is sort of ugly, because it includes the domain and log levels
verbatim. They're just plain strings on the API, there's no way the
client would know which ones are valid.

On the other hand this kills one of two uses of nmc_parse_args(), which
probably means it's not a very good abstraction and maybe we should get
rid of it altogether. It is in particular unfriendly to argument
completion.
2017-02-15 11:16:19 +01:00
Beniamino Galvani
6f3569a58a cli: remove duplicate duplicate check on nmc->complete
Fixes: a3b61303f8
2016-12-14 10:12:18 +01:00
Beniamino Galvani
20bf5ce359 cli: add DNS information to overview output
Example:

   $ nmcli
   [...]
   DNS configuration:
   	servers: 10.0.0.1
   	domains: foobar.com
   	interface: tun0
   	type: vpn

   	servers: 192.168.10.1
   	domains: home
   	interface: ens3

   	servers: fd01🔡:21
   	interface: ens3
2016-12-12 22:06:24 +01:00
Beniamino Galvani
a3b61303f8 cli: implement 'networking' subcommand using nmc_do_cmd()
It simplifies the code and doesn't require that NM is running to
display the help.
2016-12-09 17:57:49 +01:00
Lubomir Rintel
f2099f5b79 cli/general: defer printing the permissions until we know them
The async client might be constructed before we know the permissions.
2016-11-11 16:18:03 +01:00
Lubomir Rintel
01a20015e0 cli: use nmc_do_cmd to get the client and check if the daemon is running
The makes use of asynchronous client initialization, making things a bit
faster and reduces code duplication too.
2016-11-11 16:18:03 +01:00
Lubomir Rintel
3ee03afecc cli: make it possible to call sub-commands with client obtained asynchronously 2016-11-11 16:18:03 +01:00
Beniamino Galvani
e9f96024ae cli: return sane error message for D-Bus policy permission errors
The error returned to users when a load_connection(s)/set_logging call
fails due to D-Bus policy denial is a bit obscure:

  $ nmcli general logging level debug
  Error: failed to set logging: Rejected send message, 4 matched rules;
  type="method_call", sender=":1.233" (uid=1001 pid=27225 comm="nmcli
  general logging level debug ")
  interface="org.freedesktop.NetworkManager" member="SetLogging" error
  name="(unset)" requested_reply="0" destination=":1.207" (uid=0
  pid=25793 comm="/usr/sbin/NetworkManager --no-daemon ")

Convert it to a more comprehensible:

  $ nmcli general logging level debug
  Error: failed to set logging: access denied

https://bugzilla.redhat.com/show_bug.cgi?id=1362542
(cherry picked from commit 805925f9ef)
2016-08-20 10:45:55 +02:00
Alfonso Sanchez-Beato
6fb0de0a8b auth: check when setting statistics refresh rate 2016-08-17 16:08:20 +02:00
Thomas Haller
2cb18efaea permissions: properly add checkpoint-rollback permission
Fixes: a52d4654ec
2016-08-17 15:50:20 +02:00
Lubomir Rintel
8c4b749355 cli/networking: add subcommand completion 2016-08-01 13:52:36 +02:00
Lubomir Rintel
b37c109ee4 cli/radio: add subcommand completion 2016-08-01 13:52:36 +02:00
Lubomir Rintel
5305dfdf19 cli/radio: use nmc_do_cmd() 2016-08-01 13:52:36 +02:00
Lubomir Rintel
2b860e4e95 cli/general: add subcommand completion 2016-08-01 13:52:36 +02:00
Lubomir Rintel
7b6ded8cc4 cli/general: use nmc_do_cmd() 2016-08-01 13:52:36 +02:00
Lubomir Rintel
9827725210 cli: get rid of the global command completion whitelist
We're going to implement most of the missing pieces; the rest is going
to handle inability to complete itself.
2016-08-01 13:52:36 +02:00
Beniamino Galvani
e7bd55afdd cli: fix typo in overview output
Fixes: f14845cc20
2016-07-20 09:31:11 +02:00
Lubomir Rintel
f14845cc20 cli: output a short summary of devices when called without arguments
This aims to be somewhat similar to what "ifconfig" does.

https://bugzilla.gnome.org/show_bug.cgi?id=766426
2016-07-19 14:29:05 +02:00