Commit Graph

48 Commits

Author SHA1 Message Date
Jiří Klimeš
e8f5a82e22 cli: fix ambiguity of "o" (on vs off) in nmc_string_to_bool() 2014-05-15 09:50:52 +02:00
Thomas Haller
9ef23947cc all: fix various warnings detected with coverity
https://bugzilla.gnome.org/show_bug.cgi?id=728320

Signed-off-by: Thomas Haller <thaller@redhat.com>
2014-05-02 15:20:30 +02:00
Jiří Klimeš
26f8889286 cli: consolidate active and configured connections (rh #997999)
Handle connection profiles in a single 'show' command instead of 'show active'
and 'show configured'.

nmcli con show [--active] [[id|uuid|path|apath] <bla>]

nmcli con show           : display all connection profiles
nmcli con show --active  : only display active connection profiles
                           (filters out inactive profiles)

nmcli con show myeth     : display details of "myeth" profile, and also active
                           connection info (if the profile is active)
nmcli -f profile con show myeth : only display "myeth"'s static configuration
nmcli -f active  con show myeth : only display active details of "myeth"
nmcli -f connection.id,ipv4,general con show myeth
                                          : display "connection.id"a property
                                            "ipv4" setting and "GENERAL" group
                                            of active data

https://bugzilla.redhat.com/show_bug.cgi?id=997999
2014-01-23 13:45:46 +01:00
Jiří Klimeš
94bb83a370 cli: allow specifying 'group.name' syntax for '--fields'
and use it for 'nmcli device show'.

This allows filtering output not only for whole groups, but also for individual
fields in commands that print data in groups (sections).

Example:
$ nmcli -f general.device,general.driver,ipv4,ipv6.address device show eth0
GENERAL.DEVICE:                         eth0
GENERAL.DRIVER:                         e1000e
IP4.ADDRESS[1]:                         ip = 10.0.5.228/23, gw = 10.0.5.254
IP4.ADDRESS[2]:                         ip = 5.5.5.5/32, gw = 5.5.5.1
IP4.DNS[1]:                             192.168.122.1
IP4.DNS[2]:                             8.8.8.8
IP4.DOMAIN[1]:                          mycompany.com
2013-12-17 13:51:34 +01:00
Thomas Haller
97935382f4 coverity: fix various warnings detected with Coverity
These are (most likely) only warnings and not severe bugs.
Some of these changes are mostly made to get a clean run of
Coverity without any warnings.

Error found by running Coverity scan

https://bugzilla.redhat.com/show_bug.cgi?id=1025894

Co-Authored-By: Jiří Klimeš <jklimes@redhat.com>
Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-13 15:29:24 +01:00
Thomas Haller
93131b1df2 cli: fix in matching command line arguments
Ensure in matches() that a non-empty cmd is given, otherwise
as currently

  nmcli general -

matches to '-h' and is thus treated as

  nmcli general -h

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-11-11 15:27:30 +01:00
Dan Winship
0221971da5 nmcli: fix some leaks found by valgrind
https://bugzilla.gnome.org/show_bug.cgi?id=709369
2013-10-23 22:22:35 -04:00
Thomas Haller
f6703f540c nmcli: reword error message for a wrong user input in edit mode
Before, when specifying a setting.property with missing property name,
the following happened:

  nmcli> set connection.
  Error: invalid property: '' not among [...

Reword this special error case of a missing property to make it more
clear.

Signed-off-by: Thomas Haller <thaller@redhat.com>
2013-09-05 20:02:12 +02:00
Pavel Šimerda
320a9d16a3 all: replace struct in_addr with guint32 2013-08-03 00:15:07 -05:00
Jiří Klimeš
ca1c0cdaf4 cli: add 'nmcli' command for nmcli connection editor configuration
- show/hide status line:  nmcli> nmcli status-line yes | no
- editor prompt color:    nmcli> nmcli prompt-color <0-8>  (0 = normal/without color)
2013-07-22 13:37:16 +02:00
Jiří Klimeš
937eb48590 cli: 'connection edit' - edit/add connections in an interactive editor
nmcli connection edit [type <type>] [con-name <name>]

Examples:
nmcli c e
nmcli c e type ethernet
nmcli c e type wifi con-name "My home Wi-Fi"
nmcli c e type bond
...
2013-07-22 13:32:32 +02:00
Jiří Klimeš
28704d1f42 cli: 'dev wifi list' use nm_utils_ssid_to_utf8() to display SSID; add SSID-HEX
This commit removes enclosing '' from SSID.
SSID-HEX is printed as a string of hex characters (each 2 chars represent one
byte).
2013-05-31 09:38:03 +02:00
Jiří Klimeš
7fe4345d0d cli: print_required_fields() - fix non-ASCII strings alignment in multiline 2013-05-31 09:38:03 +02:00
Jiří Klimeš
e6870789b5 cli: enhance printing to align tabular output properly and not to waste space
Until now we have used a static width defined for each column for tabular
output. Even if this worked in most cases, it was not optimal, because by
using too wide columns we wasted space, and in case of a too narrow column the
alignment broke. So, we need to know the longest string in a column to be able
to align columns in the tabular output. Thus, the printing has to be postponed
till we have all data available, and can find the widest column. This value is
then used for aligning while printing the data.

Arrays of NmcOutputField (rows) are inserted into output_data array. When all
data have been added, print_data() can be used to print the whole output_data
array with proper alignment.

A single row can be printed using print_required_fields().

Also, output flags are redone to better match the new output_data array.
The flags are needed for every row (in tabular output); they are stored in
the first field (NmcOutputField) for the whole row.

Addapted set_val_str() and set_val_arr() to set value type (char * x char **).
Added set_val_strc(), set_val_arrc() for const values that should not be freed.

output_data takes ownership of the data added to it and takes care of freeing
the memory.

See e.g.
https://bugzilla.gnome.org/show_bug.cgi?id=699503
2013-05-31 09:38:03 +02:00
Jiří Klimeš
04d590a923 cli: nmc_string_to_bool() - util function for converting string to boolean
["true", "yes", "on"] -> TRUE
["false", "no", "off"] -> FALSE
2013-05-07 19:41:36 +02:00
Jiří Klimeš
ddd3ea2cd4 cli: util functions for converting string to int
nmc_string_to_int()  - converts string to signed long int (decimal)
nmc_string_to_uint() - converts string to unsigned long int (decimal)
nmc_string_to_int_base()  - converts string to signed long int with given base
nmc_string_to_uint_base() - converts string to unsigned long int with given base
2013-05-07 19:41:36 +02:00
Jiří Klimeš
8598ee1139 cli: nmc_string_is_valid() utility function
This function checks whether a string is contained among allowed strings. It
performs case-insensitive comparison and supports shortcuts if they are unique.
It returns a pointer to the found string in allowed array, or NULL.
2013-05-07 19:41:36 +02:00
Jiří Klimeš
d3ea9ee472 cli: handle NULL gracefully in nmc_arg_is_help() 2013-04-18 12:42:54 +02:00
Jiří Klimeš
7d5df73d76 cli: add nmc_arg_is_help() and use it to save some code lines 2013-04-18 11:25:49 +02:00
Pavel Šimerda
b292af8e1d trivial: avoid -Wshadow
jklimes: read vs. read(3), use 'num' instead
2013-04-15 13:43:34 +02:00
Jiří Klimeš
e2d8ca7924 cli: util function to parse command-line arguments
nmc_parse_args() - parse command-line arguments
2013-04-08 16:14:11 -05:00
Jiří Klimeš
b0bee192e8 cli: add nmc_string_to_arg_array() to split a string to arguments array 2013-04-08 16:09:23 -05:00
Jiří Klimeš
7c629bf0f4 cli: nmc_get_user_input() util function for getting user input 2013-04-08 16:09:23 -05:00
Dan Williams
a829c0439d cli: use nm_client_get_manager_running() instead of nmc_is_nm_running()
We now guarantee that NMClient won't dbus-activate NetworkManager so
there is no need for a custom function to prevent this.
2013-04-08 11:30:32 -05:00
Dan Winship
9e71bb3cd5 cli: add property get functions - returning property value for presentation
Simplify code by using property get functions, with most of them
autogenerated based on GObject properties and GValue transforms.

Based on a patch from Jiří Klimeš
2013-03-26 12:15:49 -04:00
Jiří Klimeš
113d358ce5 cli: make 'value' in NmcOutputField non const 2013-03-26 12:15:49 -04:00
Jiří Klimeš
35689c7bd0 cli: allow next_arg() to move arguments past the last one 2012-11-20 15:20:38 +01:00
Jiří Klimeš
853803c2f0 cli: use an error quark for domain in g_set_error() instead of 0 (rh #842975)
glib 2.32 makes a runtime check that domain is not NULL:
GLib-WARNING **: (gerror.c:390):g_error_new_valist: runtime check failed: (domain != 0)
2012-07-25 13:57:45 +02:00
Jiří Klimeš
716a09d7ac cli: use "--" instead of "no set" for NULL strings 2012-06-04 12:25:43 +02:00
Jiří Klimeš
c878ad8214 cli: trivial, fix up spacing 2012-04-28 22:54:02 +02:00
Jiří Klimeš
38a988cb5e cli: add 'connect to SSID' feature: nmcli dev wifi connect <SSID> ...
This is similar to clicking a Wi-Fi network's SSID in a GUI applet.
The command does this:
- creates new connection (fills the user data specified via options, the
  connection is then completed with default parameters by NM)
- and then activates the connection on a Wi-Fi device.

WPA-Enterprise is not supported as it requires a plethora of parameters and
they can't be obtained automatically.
Also, the created connection uses 'auto' IP method, which means that if the
Wi-Fi network doesn't support DHCP, the connection will albeit be created,
however the activation will fail (IP configuration won't be available).
2012-04-28 22:33:30 +02:00
Jiří Klimeš
a2e86dfb7d cli: fix a crash (due to freeing static string) 2012-01-06 15:20:15 +01:00
Jiří Klimeš
e4327518f3 cli: move helper IP conversion functions from devices.c to utils.c 2012-01-05 16:36:42 +01:00
Jiří Klimeš
c15d047b46 cli: allow field values to be null-terminated string arrays
Field values can now be string arrays. print_fields() recognizes the format and
prints values accordingly.
Setter functions was added to facilitate setting string vs. array:
set_val_str(), set_val_arr()
2012-01-03 15:07:17 +01:00
Jiří Klimeš
785c1495ef cli: increase values indentation in multiline mode to align printed text 2011-09-07 12:20:56 +02:00
Jiří Klimeš
a9a30eb08c cli: compare nmcli and NM versions
nmcli gets NM version and compares it with its own and complains
when they differ. This is to indicate that the results are not reliable,
because the API could differ. '--nocheck' switches the checks off.
2011-02-16 17:36:50 +01:00
Jiří Klimeš
5f6b68862e cli: fix "format not a string literal and no format arguments" cc error
The string could contain printf format sequences.
2011-02-10 16:30:00 +01:00
Jiří Klimeš
f29b709590 cli: improve/add NM running checks
Check whether NetworkManager is running and return new error
NMC_RESULT_ERROR_NM_NOT_RUNNING when appropriate.
2011-02-10 14:39:47 +01:00
Jiří Klimeš
d1f63c62f0 cli: align UTF-8 strings properly
Not all utf-8 characters occupy 1 screen column. Some may be 2-column
wide, some are unprintable - zero columns.
2010-04-26 17:32:18 +02:00
Jiří Klimeš
8b0b9c29c1 cli: Remove obsolete print_table_* functions 2010-03-24 23:36:50 +01:00
Jiří Klimeš
1e329c5c0c cli: Convert SSID to a printable form
If SSID is a UTF-8 string, it is printed as it is, but enclosed in quotes.
Otherwise the bytes are converted to hex string (in uppercase).
The added quotes for UTF-8 string allow to disambiguate the two forms.
2010-03-24 23:28:00 +01:00
Jiří Klimeš
a91da03b65 cli: 'dev list' adjustments
Modifications are mainly for multiline mode to ease parsing - each
field name is prefixed with a section name.
'dev list' now also supports printing particular sections specifed via
'--fields' option.
2010-03-24 19:05:35 +01:00
Jiří Klimeš
8846bd83ad cli: print_fields(): don't segfault when a value is not set 2010-03-24 12:47:53 +01:00
Jiří Klimeš
21638ff470 cli: convert 'dev list' to new format; checking options validity for terse 2010-03-22 18:43:28 +01:00
Jiří Klimeš
6ab52b33ee cli: print_fields() adjustments; error messages fixes 2010-03-20 14:08:06 +01:00
Jiří Klimeš
3f92bb3c2e cli: fix a memory leak 2010-03-19 15:46:25 +01:00
Jiří Klimeš
55949277bd cli: changing nmcli output to better fit both computer and human needs
The output is basically tabular with fields (columns) presenting specific pieces of info.
Each line represents a single object. It's possible to switch to multiline output using
'--multiline' option. In that mode single object is presented on more lines - each field
on its line.
Terse mode now uses ':' as field separator. It also escapes all occurences of ':' and '\'
inside field values to ease parsing. The escaping behaviour can be controlled through
'--escape' option. By default, escaping is switched on in tabular mode. When using terse
mode ('--terse'), '--fields' option is mandatory for specifying required fields. That helps
for flexibility and backwards compatibility.
Not all output is converted yet.
2010-03-18 15:39:15 +01:00
Jirka Klimes
c2ec07f17d cli: add initial pieces of nmcli 2010-02-25 09:52:30 -08:00