summaryrefslogtreecommitdiff
path: root/clients/cli/utils.h
Commit message (Collapse)AuthorAgeFilesLines
* 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
|
* cli: fix signature of NMMetaAbstractType:get_fcn()Thomas Haller2017-04-051-7/+7
| | | | | | | | Depending on the get_type argument, we don't only want to return strings, but arbitrary pointers. The out_to_free argument still makes sense, but depending on the get-type you must know how to free the pointer.
* cli: move NmcMetaGenericInfo to "utils.h"Thomas Haller2017-04-051-0/+27
|
* cli: add nmc_output_selection_create() to parse field selectionThomas Haller2017-04-051-1/+18
| | | | | nmc_output_selection_create() returns a less opaque result then a GArray and a GPtrArray for the groups.
* cli: split tracking of meta data out of NmcOutputFieldThomas Haller2017-04-051-3/+3
| | | | | | | | | | | | | | | | | | | | | | 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.
* cli: pass arguments for print_data separately of NmcOutputDataThomas Haller2017-04-051-1/+5
| | | | | Don't pass on large structs of input arguments. It only convolutes which arguments are passed, and where they come from.
* cli: merge NmcPrintFields into NmcOutputData and pass it directly to ↵Thomas Haller2017-04-051-1/+6
| | | | print_required_fields()
* cli: use enum NmcOfFlags instead of plain integer flags and pass to ↵Thomas Haller2017-04-051-1/+1
| | | | print_required_fields()
* nmcli: allow cmd specific option parsing in next_arg() funcFrancesco Giudici2017-04-051-1/+1
| | | | | | | | | | | | | | | | | | | | | 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
* cli: split print_data() in a part with and without side-effectsThomas Haller2017-03-301-2/+2
| | | | | | 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.
* cli: split output data from NmCli to a separate fieldThomas Haller2017-03-301-1/+1
|
* cli: separate input and in-out arguments in print_data()Thomas Haller2017-03-301-2/+3
| | | | | Don't pass down the entire NmCli instance. The output_data array is modified by print_data(), the rest is read-only input.
* cli: pass use_colors as separate option instead of global nmcThomas Haller2017-03-301-1/+1
| | | | | | 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.
* cli: move utils function from common.h to nm-meta-setting-desc.cThomas Haller2017-03-301-31/+0
| | | | | | 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.
* cli: add values_func() to NmcPropertyInfo and use for "connection" settingThomas Haller2017-03-301-1/+1
|
* cli: add NmCli argument to next_arg()Lubomir Rintel2017-03-281-1/+1
| | | | Will be useful in next commit.
* nmcli: don't enforce anymore the -f(ields) option in -t(erse) modeFrancesco Giudici2017-03-281-1/+0
|
* cli: make match() return booleanLubomir Rintel2017-02-151-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* macros: add macro _nm_printf() for function attributeThomas Haller2016-06-051-1/+1
|
* build: avoid compiler warnings about non-constant format strings ↵Thomas Haller2016-06-051-1/+1
| | | | (-Wformat-nonliteral)
* cli: remove unused functionsThomas Haller2016-05-031-3/+0
|
* cli: remove version check against NMFrancesco Giudici2016-04-281-1/+0
| | | | | | | | | | | | 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
* cli: move the decision whether to use colors to nmc_colorize()Lubomir Rintel2015-12-051-1/+1
| | | | | This allows us to use a conditionally colorized output outside print_required_fields().
* cli: take color name arguments for "nmcli prompt-color" in editor (bgo #744936)Jiří Klimeš2015-06-111-0/+1
| | | | | | | | | 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
* cli: add nmc_string_to_tristate()Beniamino Galvani2015-06-091-0/+7
|
* cli: add @brackets parameter to nmc_util_strv_for_displayJiří Klimeš2015-05-281-1/+1
|
* cli: don't return empty strings in nmc_string_to_arg_array()Jiří Klimeš2015-03-121-1/+2
| | | | and unquote strings in the array if required.
* nmcli: add support for terminal formatting, like bold, dim, underline, etc.Jiří Klimeš2015-02-231-1/+3
|
* nmcli: add support for printing color stringsJiří Klimeš2015-02-231-0/+1
|
* nmcli: make filtering color sequences a utility functionJiří Klimeš2015-02-231-1/+3
| | | | The code will be used on other places too.