summaryrefslogtreecommitdiff
path: root/clients/cli/utils.h
Commit message (Collapse)AuthorAgeFilesLines
* format: replace tabs for indentation in code commentsac/clang-formatThomas Haller2020-09-281-6/+6
| | | | | | | | | | | | sed -i \ -e 's/^'$'\t'' \*/ */g' \ -e 's/^'$'\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t'' \*/ */g' \ -e 's/^'$'\t\t\t\t\t\t\t'' \*/ */g' \ $(git ls-files -- '*.[hc]')
* all: reformat all with new clang-format styleAntonio Cardace2020-09-281-295/+296
| | | | | | | | | | | | Run: ./contrib/scripts/nm-code-format.sh -i ./contrib/scripts/nm-code-format.sh -i Yes, it needs to run twice because the first run doesn't yet produce the final result. Signed-off-by: Antonio Cardace <acardace@redhat.com>
* cli: add nmc_meta_generic_get_str_i18n_null() helperThomas Haller2020-07-031-0/+18
| | | | (cherry picked from commit 05a84be550d70e3f155372616db611ea153d5683)
* all: add device.path propertyBeniamino Galvani2020-06-121-0/+1
| | | | | Add a device property to expose its path as reported in the ID_PATH udev property.
* cli: mark argv argument for command line parsing as constThomas Haller2020-04-101-2/+2
| | | | | | | | | It's bad style to pass the argv argument around and mutate it. We shouldn't mutate it, and not assume that it stays around after the function returns to the caller (meaning, we should clone the array if we intend to use it later). Add const specifier.
* cli: avoid using nm_cli global variable in print_data()Thomas Haller2020-04-041-0/+2
|
* cli: make nmc_meta_environment_arg const pointerThomas Haller2020-04-041-1/+1
| | | | | Of course, we later pass the point on, where we need to cast the constness away again. This is more a reminder that we aren't suppost to change the variable.
* cli: expose device D-Bus pathBeniamino Galvani2019-12-101-0/+1
| | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1745574 (cherry picked from commit 622eef4882028fa49a1ffd836ffdb6c633863197)
* all: add device carrier flagBeniamino Galvani2019-11-221-0/+1
| | | | | | | | | Add a new 'carrier' flag to the InterfaceFlags property of devices to indicate the current carrier state. The new flag is equivalent to the 'lower-up' flag for all devices except the ones that use a non-standard carrier detection mechanism like NMDeviceAdsl.
* cli: print interface flagsBeniamino Galvani2019-11-221-0/+4
|
* nmcli: show IP interface name when doing 'nmcli connection show <PROFILE>'Antonio Cardace2019-11-061-0/+1
| | | | | | https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/218 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/322
* all: unify format of our Copyright source code commentsThomas Haller2019-10-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```bash readarray -d '' FILES < <( git ls-files -z \ ':(exclude)po' \ ':(exclude)shared/c-rbtree' \ ':(exclude)shared/c-list' \ ':(exclude)shared/c-siphash' \ ':(exclude)shared/c-stdaux' \ ':(exclude)shared/n-acd' \ ':(exclude)shared/n-dhcp4' \ ':(exclude)src/systemd/src' \ ':(exclude)shared/systemd/src' \ ':(exclude)m4' \ ':(exclude)COPYING*' ) sed \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[-–] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C1pyright#\5 - \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) *[,] *\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C2pyright#\5, \7#\9/' \ -e 's/^\(--\|#\| \*\) *\(([cC]) *\)\?Copyright \+\(\(([cC])\) \+\)\?\(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/\1 C3pyright#\5#\7/' \ -e 's/^Copyright \(\(20\|19\)[0-9][0-9]\) \+\([^ ].*\)$/C4pyright#\1#\3/' \ -i \ "${FILES[@]}" echo ">>> untouched Copyright lines" git grep Copyright "${FILES[@]}" echo ">>> Copyright lines with unusual extra" git grep '\<C[0-9]pyright#' "${FILES[@]}" | grep -i reserved sed \ -e 's/\<C[0-9]pyright#\([^#]*\)#\(.*\)$/Copyright (C) \1 \2/' \ -i \ "${FILES[@]}" ``` https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/298
* all: manually drop code comments with file descriptionThomas Haller2019-10-011-2/+1
|
* all: SPDX header conversionLubomir Rintel2019-09-101-14/+1
| | | | | $ find * -type f |xargs perl contrib/scripts/spdx.pl $ git rm contrib/scripts/spdx.pl
* wifi: expose IBSS_RSN capabilityBeniamino Galvani2019-08-261-0/+1
| | | | | | | The new capability indicates whether the device supports WPA2/RSN in an IBSS (ad-hoc) network. https://bugzilla.gnome.org/show_bug.cgi?id=757823
* clients: Wi-Fi Mesh supportlr/wifi-meshLubomir Rintel2019-07-291-0/+1
| | | | | Allow setting mesh mode in wireless connections and recognize the Mesh support as indicated by the device flags.
* cli: don't use global variable nm_cli in nmc_terminal_spawn_pager()Thomas Haller2018-10-101-1/+1
| | | | | | print_required_fields() still accesses the global variable. We can only move the uses of globals up the call-stack, one bit at a time.
* cli: print per-device & per-AF connectivity statusLubomir Rintel2018-09-241-0/+4
|
* cli: add additional user-data argument to get_fcn()Thomas Haller2018-07-091-0/+2
| | | | | | | | | | | | | | | | | | | 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.
* cli: rework printing of "wired" and "wifi" device detailsThomas Haller2018-07-091-0/+21
|
* cli: rework printing of "capabilities" device detailsThomas Haller2018-07-091-0/+6
|
* cli: rework printing of "connections" device detailsThomas Haller2018-07-091-0/+4
|
* cli: rework printing of "general" device detailsThomas Haller2018-07-091-0/+26
|
* cli: rework printing of device statusThomas Haller2018-07-091-0/+9
|
* cli: rework printing of dhcp optionsThomas Haller2018-07-091-0/+3
|
* cli: rework printing of vpn active-connection propertiesThomas Haller2018-07-091-7/+31
| | | | use nmc_print() for the job.
* cli: add connection FILENAME fieldLubomir Rintel2018-06-111-0/+1
| | | | | | | This allows the user to look up the file where the connection is stored. Useful especially for ifcfg users. Not shown by default.
* cli: rework printing of general active-connection propertiesThomas Haller2018-06-011-0/+14
| | | | | | | | | | | | | | | | | use nmc_print() for the job. Also, localize non-terse output. Also, fix bug with $ nmcli c s /org/freedesktop/NetworkManager/ActiveConnection/1 if active connection #1 is invisible to the user. Also, previously, fill_output_active_connection() wrongly tries to write to a field that doesn't exist: set_val_strc (arr, 13-idx_start, s_con ? nm_setting_connection_get_slave_type (s_con) : NULL);
* cli: rework printing of `nmcli connection` for multiple active connectionsThomas Haller2018-06-011-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The output of `nmcli connection show` contains also information about whether the profile is currently active, for example the device and the current (activation) state. Even when a profile can be activated only once (without supporting mutiple activations at the same time), there are moments when a connection is activating and still deactivating on another device. NetworkManager ensures in the case with single activations that a profile cannot be in state "activated" multiple times. But that doesn't mean, that one profile cannot have multiple active connection which reference it. That was already handled wrongly before, because `nmcli connection show` would only search the first matching active-connection. That is, it would arbitrarily pick an active connection in case there were multiple and only show activation state about one. Furthermore, we will soon also add the possibility, that a profile can be active multiple times (at the same time). Especially then, we need to extend the output format to show all the devices on which the profile is currently active. Rework printing the connection list to use nmc_print(), and fix various issues. - as discussed, a profile may have multiple active connections at each time. There are only two possibilities: if a profile is active multiple times, show a line for each activation, or otherwise, show the information about multiple activations combined in one line, e.g. by printing "DEVICE eth0,eth1". This patch, does the former. We will now print a line for each active connection, to show all the devices and activation states in multiple lines. Yes, this may result in the same profile being printed multiple times. That is a change in behavior, and inconvenient if you do something like for UUID in $(nmcli connection show | awk '{print$2}'); do ... However, above is anyway wrong because it assumes that there are no spaces in the connection name. The proper way to do this is like for UUID in $(nmcli -g UUID connection show); do ... In the latter case, whenever a user selects a subset of fields (--fields, --get) which don't print information about active connections, these multiple lines are combined. So, above still works as expected, never returning duplicate UUIDs. - if a user has no permissions to see a connection, we previously would print "<invisible> $NAME". No longer do this but just print the ID was it is reported by the active-connection. If the goal of this was to prevent users from accidentally access the non-existing connection by $NAME, then this was a bad solution, because a script would instead try to access "<invisible> $NAME". This is now solved better by hiding the active connection if the user selects "-g NAME". - the --order option now sorts according to how the fields are shown. For example, with --terse mode, it will evaluate type "802-11-wireless" but with pretty mode it will consider "wifi". This may change the ordering in which connections are shown. Also, for sorting the name, we use g_utf8_collate() because it's unicode.
* cli: use macro for list of argument for NmcMetaGenericInfo.get_fcn()th/cli-connection-handlingThomas Haller2018-05-141-9/+13
| | | | | | | | | | | | | | | The reasons are: - I want to locate all implmenetations of the get_fcn() handler. By consistently using this macro, you can just grep for the macro and find them all. - all implementations should follow the same style. This macro enforces the same names for arguments and avoids copy&paste. - if we are going to add or change an argument, it becomes easier. That's because we can easily identify all implementation and can change arguments in one place.
* cli: add helper methods for implementing NmcMetaGenericInfo's get_fcn()Thomas Haller2018-05-141-0/+40
|
* cli: add and use macro for creating NmcMetaGenericInfo parent groupsThomas Haller2018-05-141-0/+6
|
* cli: use a palette to implement coloringLubomir Rintel2018-05-101-8/+5
| | | | | | | | | | | 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.
* cli: rework enabling and disabling colorsLubomir Rintel2018-05-101-2/+1
| | | | | | | | | | | | | | | | This actually makes very little difference at the moment, but will make things more confortable later on, when the logic of enabling/disabling coloring will involve terminal-colors.d(5). Instead of deciding whether to use colors lazily with use_colors(), it's done very early on nmcli initialization and a boolean use_colors field is stored in the NmcConfig instance instead of the raw tristate option of NmcColorOption type (which is now confined to nmcli.c). Wherever the NmcColorOption was used previously, the whole NmcConfig instance is passed around. That might seem pointless (since only the use_colors boolean is actually used at the moment), but will be utilized to pass around the actual color palette in future.
* cli: drop --prompt-colorLubomir Rintel2018-05-101-2/+1
| | | | | | | | | It's undocumented, useless, somewhat expensive in volume of code and probably just downright stupid. We'll get a more general way to set colors. Hacking in some code to keep this working wouldn't be too difficult, but it seems entirely pointless.
* clients: change nm_meta_abstract_info_get() to report defaultsBeniamino Galvani2018-04-131-0/+1
| | | | | Return a boolean to indicate whether the value is the default one, so that the caller can choose to hide it.
* cli: drop nmc_strsplit_set()Thomas Haller2017-12-121-1/+0
| | | | | | | | 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).
* cli: refactor printing IP6 device infoThomas Haller2017-09-261-0/+7
|
* clients: make meta data subtypes of NMObjBaseInstThomas Haller2017-07-051-1/+4
| | | | | Yes, this wastes 4 times an unused GType instance in the class structure.
* cli: spawn a pager when running on a terminalLubomir Rintel2017-05-151-1/+3
| | | | | | | | 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.
* cli: don't mark field names for translationThomas Haller2017-04-231-1/+1
| | | | | | | | | | | | | | | | 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.
* cli/trivial: remove whitespace between N_ macro and parenthesisThomas Haller2017-04-191-1/+1
| | | | | For _() and N_() we don't have a space before the parenthesis. Be consistent about that.
* cli: move parsing of meta data fieldsThomas Haller2017-04-131-20/+0
|
* cli/trivial: rename NmcOutputSelectionItem typeThomas Haller2017-04-131-10/+10
|
* cli: cleanup meta data virtual function argumentsThomas Haller2017-04-121-0/+3
| | | | | | | | | - 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.
* cli: use nmc_print() to output device's IP4 infoThomas Haller2017-04-121-2/+18
| | | | | The IP4 info adds a new type: to expose strv arguments for addresses, etc.
* cli: use nmc_print() to output `nmcli general logging`Thomas Haller2017-04-121-0/+4
|
* cli: use nmc_print() to output `nmcli general permissions`Thomas Haller2017-04-121-0/+6
| | | | Add also colors for the output values.
* cli: implement new nmc_print() command to generically output cli dataThomas Haller2017-04-121-2/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* cli: move and rename TermColor and TermFormatThomas Haller2017-04-051-6/+6
|