Commit Graph

101 Commits

Author SHA1 Message Date
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
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
d0ce5fc550 cli: cleanup get_value_to_print() util
Don't cast const strings to non-const. And don't track
whether to free a variable in a boolean. Instead, assign
ownership to variables that get destroyed when the function
returns.
2017-03-30 13:24:55 +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
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
cb66cf96d7 cli: add values_func() to NmcPropertyInfo and use for "connection" setting 2017-03-30 13:09:55 +02:00
Thomas Haller
4e91492b76 cli: rework property handling via NmcPropertyInfo for NMSettingConnection
Add an improved way of tracking meta data about settings.

E.g. it is wrong to generate for each property a nmc_property_*_get_*()
function. Instead, there should be a meta data about the property
itself, and a mechanism to retrieve the property.

For now, only do this for NMSettingConnection and keep all the existing
infrastructure in place. Later on all settings shall be moved.

Especially to accomodate NmcOutputField mangles the concept of
setting-meta data, formatting options, and collecting output results.
It's a total hack, that will be need fixing later.
2017-03-30 13:09:55 +02:00
Francesco Giudici
0e73a06646 nmcli: fix nmcli connection edit
fix extra parameters check in nmc_parse_args()
e.g.: nmcli connection edit type ethernet

Fixes: 16902a2be6
2017-03-29 11:34:13 +02:00
Lubomir Rintel
f909ef421b cli: check for global options before each agument
Turn --ask and --show-secrets into global options. This is for user
comfort, see: rh #1351263.
2017-03-28 15:32:05 +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
8bfb9989cd nmcli: fix colorize_string() signature in order to return static char *
moved from: char *colorize_string (..., gboolean &dealloc)
to: const char *colorize_string (..., char **out_to_free)

No more needed to cast (char *) on a (const char *).

Fixed also get_value_to_print() which relies on colorize_string()
2017-03-28 10:55:00 +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
Francesco Giudici
7b589a0aef nmcli: refactor print_required_fields
When only the main header should be printed and output mode
is 'pretty' skip the construction of the string containing
field values as it will not be used.
2017-03-28 10:55:00 +02:00
Francesco Giudici
6520cf1171 nmcli: always print "--" for empty or unset values in normal/pretty output
This was already true for tabular ouput mode.
Align to this behavior when printing in multiline mode.
2017-03-28 10:55:00 +02:00
Francesco Giudici
3e3d36450c nmcli: don't substitute empty strings with "--" in terse mode 2017-03-28 10:55:00 +02:00
Lubomir Rintel
bc6a383dd7 cli: fix match()
Fixes: 84c484ed5b
2017-02-16 10:39:08 +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
Thomas Haller
0bdcab100c all: cleanup includes in header files
- don't include "nm-default.h" in header files. Every source file must
  include as first header "nm-default.h", thus our headers get the
  default include already implicitly.

- we don't support compiling NetworkManager itself with a C++ compiler. Remove
  G_BEGIN_DECLS/G_END_DECLS from internal headers. We do however support
  users of libnm to use C++, thus they stay in public headers.

(cherry picked from commit f19aff8909)
2016-08-17 19:51:17 +02:00
Thomas Haller
466bf2f633 build: avoid compiler warnings about non-constant format strings (-Wformat-nonliteral) 2016-06-05 12:22:01 +02:00
Thomas Haller
a9908c012c cli: remove unused functions 2016-05-03 11:53:15 +02:00
Francesco Giudici
3c67a1ec5e cli: remove version check against NM
When performing NM package upgrade the new version of nmcli will be immediately
available while NM daemon will not, as it would not restart in order to avoid
to disrupt connectivity. This could create issues with tools leveraging
on nmcli output (till reboot). As apart from this case it is very unlikely
that a user can have this nmcli / NM daemon version mismatch situation,
the check could cause more harm than benefit in real user case
scenarios.

https://bugzilla.redhat.com/show_bug.cgi?id=1291785
2016-04-28 09:35:20 +02:00
Thomas Haller
8bace23beb all: cleanup includes and let "nm-default.h" include "config.h"
- All internal source files (except "examples", which are not internal)
  should include "config.h" first. As also all internal source
  files should include "nm-default.h", let "config.h" be included
  by "nm-default.h" and include "nm-default.h" as first in every
  source file.
  We already wanted to include "nm-default.h" before other headers
  because it might contains some fixes (like "nm-glib.h" compatibility)
  that is required first.

- After including "nm-default.h", we optinally allow for including the
  corresponding header file for the source file at hand. The idea
  is to ensure that each header file is self contained.

- Don't include "config.h" or "nm-default.h" in any header file
  (except "nm-sd-adapt.h"). Public headers anyway must not include
  these headers, and internal headers are never included after
  "nm-default.h", as of the first previous point.

- Include all internal headers with quotes instead of angle brackets.
  In practice it doesn't matter, because in our public headers we must
  include other headers with angle brackets. As we use our public
  headers also to compile our interal source files, effectively the
  result must be the same. Still do it for consistency.

- Except for <config.h> itself. Include it with angle brackets as suggested by
  https://www.gnu.org/software/autoconf/manual/autoconf.html#Configuration-Headers
2016-02-19 17:53:25 +01:00
Lubomir Rintel
0aed7b5be6 cli: disable colors on dumb terminals
Nothing too sophisticated; just a simple way to get an color-less output on a
pty that wouldn't confuse the test suite.
2016-02-17 19:04:39 +01:00
Lubomir Rintel
67caad44c3 cli: move the decision whether to use colors to nmc_colorize()
This allows us to use a conditionally colorized output outside
print_required_fields().
2015-12-05 12:05:17 +01:00
Jiří Klimeš
b45bd96d89 cli: trivial: correct argument description for nmc_parse_args() 2015-10-23 12:28:29 +02:00
Dan Winship
22e1a97e12 all: drop includes to <glib/gi18n.h> for "nm-default.h"
The localization headers are now included via "nm-default.h".

Also fixes several places, where we wrongly included <glib/gi18n-lib.h>
instead of <glib/gi18n.h>. For example under "clients/" directory.
2015-08-05 15:35:51 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Jiří Klimeš
3641ddb00a cli: take color name arguments for "nmcli prompt-color" in editor (bgo #744936)
Adjust nmcli prompt-color description and make it more friendly for
translators.

nmcli> nmcli prompt-color green

https://bugzilla.gnome.org/show_bug.cgi?id=744936
2015-06-11 10:00:54 +02:00
Beniamino Galvani
bd4e1f37f8 cli: fix error message localization
Valid values must not be translated in error messages generated in
nmc_string_to_bool() and nmc_string_to_tristate().
2015-06-09 18:23:12 +02:00
Beniamino Galvani
609f4f37c0 cli: add nmc_string_to_tristate() 2015-06-09 18:11:25 +02:00
Jiří Klimeš
5e1a7ffb39 cli: add @brackets parameter to nmc_util_strv_for_display 2015-05-28 10:13:51 +02:00
Jiří Klimeš
661ef3cd46 cli: don't return empty strings in nmc_string_to_arg_array()
and unquote strings in the array if required.
2015-03-12 15:32:39 +01:00
Jiří Klimeš
758e488f13 nmcli: add global '--colors' option for controlling color output
nmcli -c auto  ->  colors will only be used when stdout is a terminal
nmcli -c yes   ->  colors will be enabled unconditionally
nmcli -c no    ->  colors will be disabled unconditionally
2015-02-23 09:24:21 +01:00
Jiří Klimeš
bc265d4372 nmcli: add support for terminal formatting, like bold, dim, underline, etc. 2015-02-23 09:24:21 +01:00
Jiří Klimeš
b77ec93d99 nmcli: add support for printing color strings 2015-02-23 09:24:21 +01:00
Jiří Klimeš
4e0e61f669 nmcli: pay attention to color escape sequencies when counting string length
This is to properly align the columns on screen.
2015-02-23 09:24:21 +01:00
Jiří Klimeš
3e8fc26d25 nmcli: make filtering color sequences a utility function
The code will be used on other places too.
2015-02-23 09:24:21 +01:00
Jiří Klimeš
bcd5b2cdc1 cli: fix DEADCODE (CWE-561) found by coverity
Error: DEADCODE (CWE-561): [#def3]
NetworkManager-0.9.11.0/clients/cli/utils.c:488: cond_notnull: Condition "input", taking true branch. Now the value of "input" is not "NULL".
NetworkManager-0.9.11.0/clients/cli/utils.c:517: notnull: At condition "input", the value of "input" cannot be "NULL".
NetworkManager-0.9.11.0/clients/cli/utils.c:517: dead_error_condition: The condition "input" must be true.
NetworkManager-0.9.11.0/clients/cli/utils.c:517: dead_error_line: Execution cannot reach the expression """" inside this statement: "g_set_error(error, 1U, 0, d...".
2014-12-12 22:43:33 +01:00
Lubomir Rintel
1c9b16b2f2 cli: Add mode option for wifi connecitons
Only default (infrastructure) mode connections can be created and as it's not
possible to write mode=ap connections with ifcfg-rh plugins, they can't be
switched to mode=ap.
2014-10-23 18:34:39 +02:00
Dan Winship
1b74e77f9f cli: use g_print/g_printerr rather than printf/fprintf
Use g_print() and g_printerr(), which wrap printf() and
fprintf(stderr,...), but handle conversion from UTF-8 if the locale is
using a different character set.
2014-09-27 11:45:53 -04:00
Dan Winship
1838db9e71 all: remove a bunch of unnecessary dbus/dbus-glib includes 2014-09-03 10:45:24 -04:00
Thomas Haller
ef24273104 cli: fix warning in parse_output_fields() about strict-overflow
gcc warns:

    make[4]: Entering directory `./NetworkManager/cli/src'
      CC       utils.o
    utils.c: In function ‘parse_output_fields’:
    utils.c:707:7: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
        if (found) {
           ^

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-08-01 13:17:01 +02:00