1. 12 Feb, 2019 2 commits
  2. 02 Nov, 2018 1 commit
  3. 10 Oct, 2018 1 commit
  4. 15 Sep, 2018 1 commit
  5. 11 Aug, 2018 1 commit
  6. 10 Aug, 2018 1 commit
    • Thomas Haller's avatar
      cli: add functionality to hide properties from output · 582ee911
      Thomas Haller authored
      Historically, nmcli printed all fields during operations like
      `nmcli connection show "$PROFILE"`. As we supported more and
      more options, this resulted in a verbose output, of most properties
      just being the default values.
      
      To counter that, we added the '-overview' option. When given,
      it would hide options that are set at their default. This option
      was not the default, to preserve established behavior.
      
      However, for new options, we can afford to hide them. Add a mechanism,
      that property getters can mark their value to be hidden. At the moment,
      there is no way to show these properties. However, we could add a
      '-verbose' option, with the opposite meaning of '-overview'. Anyway,
      that does not seem necessary at the moment.
      
      Hiding properties from output is only acceptable for new properties
      (otherwise we badly change behavior), and if the properties are set
      at their default values (otherwise, we hide important information).
      582ee911
  7. 25 Jul, 2018 8 commits
    • Thomas Haller's avatar
    • Thomas Haller's avatar
      cli: don't explicitly unset out_to_free argument in NMMetaType.get_nested() · 41810aad
      Thomas Haller authored
      The virtual function NMMetaType.get_nested() has only one caller:
      nm_meta_abstract_info_get_nested(). That caller makes sure to
      always pass in an @out_to_free argument, and that it is initialized
      to NULL.
      41810aad
    • Thomas Haller's avatar
      cli: drop local variable multiline in _print_do() · 07ea0007
      Thomas Haller authored
      The local variable was just a copy of the (unchanging)
      configuration nmc_config->multiline_output.
      
      It is complicated enough to understand how nmc_config->print_output
      and nmc_config->multiline_output affects nmc_print(). Don't use an
      alias when referencing to nmc_config->multiline_output because it
      hides where the value is used and where it causes a difference.
      07ea0007
    • Thomas Haller's avatar
      cli: simplify tracking of parent column in PrintDataCol structure · 66e5f133
      Thomas Haller authored
      PrintDataCol contains a reference to the parent structure, for which
      it was created. Previously, that was expressed via the "parent_idx"
      field, which is an index into the list of all PrintDataCol entries.
      
      That is inconvenient. Resolve the index to the actual pointer.
      
      Note that during _output_selection_append() we still need to use
      the index instead of resolving the pointer right away. That is because
      _output_selection_append() grows the GArray into which the parent_idx
      pointers to. So, obtaining the real pointer at that point would result
      in using a dangling pointer later on.
      
      Introduce a new step _output_selection_complete() which converts the
      index into the actual pointer.
      66e5f133
    • Thomas Haller's avatar
      cli: minor cleanup explicitly checking print_output · ac07cbb9
      Thomas Haller authored
      The print-output knows three modes: NORMAL, PRETTY, TERSE.
      Never compare whether a mode is != a particular mode.
      
      Instead, always explicitly check for the modes for which we enable a
      particular behavior.
      
      The effect is, that we always do something when the mode is set to a
      particular value. We don't ever do something, if the mode is not set to
      a particular value. Consistently opt-in is easier to understand.
      ac07cbb9
    • Thomas Haller's avatar
      cli: minor cleanup evaluating print_output · 8f037a11
      Thomas Haller authored
      The print-output knows three modes: NORMAL, PRETTY, TERSE.
      Instead of using local variables "pretty" and "terse",
      check for the output mode directly.
      
      Note how we have tree modes, so mapping them to two boolean
      variables is confusing. Especially at one place where we did:
        pretty = (nmc_config->print_output != NMC_PRINT_TERSE);
      while at other places:
        pretty = (nmc_config->print_output == NMC_PRINT_PRETTY);
      8f037a11
    • Thomas Haller's avatar
      cli: minor cleanup in _print_data_cell_clear_text() · e912ca76
      Thomas Haller authored
      It wasn't entirely clear what this was doing.
      
      Like before, free and clear the text pointers.
      However, also always reset the text_format back to PLAIN.
      e912ca76
    • Thomas Haller's avatar
      cli: fix skipping columns with all default-values · 9c51ebc2
      Thomas Haller authored
      The header-cell is the header for a column with possibly many
      rows.
      
      We must not set:
        header_cell->skip = nmc_config->overview && is_default;
      for a particular cell, because it does not take into accound
      the neighbouring rows. It is only correct, if there is only
      one row.
      
      Invert the logical meaning and rename "strip" to "to_print".
      Each cell then can opt-in, whether it needs to be printed.
      Only if no cell opts-in, it will be skipped.
      
      Fixes: 9a19bbcb
      9c51ebc2
  8. 09 Jul, 2018 1 commit
    • Thomas Haller's avatar
      cli: add additional user-data argument to get_fcn() · ba350a34
      Thomas Haller authored
      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.
      ba350a34
  9. 15 Jun, 2018 1 commit
    • Thomas Haller's avatar
      cli: fix printing multi-line output when there is nothing to print · 4e7ae3da
      Thomas Haller authored
      When a property getter returns an empty/missing strv-array, in multi-line
      mode we should not print any lines.
      
      To get that right, we must mark the cell as STRV type, even if there is no value
      provided.
      
      Previously, with text_out_flags having NM_META_ACCESSOR_GET_OUT_FLAGS_STRV
      and value being NULL, we would not set
        cell->text_format = PRINT_DATA_CELL_FORMAT_TYPE_STRV;
      and thus, later on the value would be treated as a missing (plain)
      string.
      4e7ae3da
  10. 13 Jun, 2018 1 commit
    • Lubomir Rintel's avatar
      cli/utils: make next_arg() recognize arguments that are not in "--option" form · e6abc96e
      Lubomir Rintel authored
      This is going to make it possible to parse and complete argument lists in one go:
      
        -nmc_complete_strings (*argv, "ifname", "bssid", NULL);
        -next_arg (nmc, &argc, &argv, NULL);
        -if (strcmp (*argv, "ifname") == 0)
        -...
        -else if (strcmp (*argv, "bssid") == 0)
        -...
        +option = next_arg (nmc, &argc, &argv, "ifname", "bssid", NULL)
        +switch (option) {
        +case 1:
        +...
        +case 2:
        +...
      
      Beautiful.
      e6abc96e
  11. 01 Jun, 2018 1 commit
    • Thomas Haller's avatar
      cli: rework printing of `nmcli connection` for multiple active connections · a1b25a47
      Thomas Haller authored
      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.
      a1b25a47
  12. 25 May, 2018 1 commit
    • Thomas Haller's avatar
      cli: avoid bogus line seprator in pretty-output · e1bbc2e1
      Thomas Haller authored
      This bug resulted in spurious lines with "--pretty --mode tabular",
      whenever nmc_print() was called with multiple rows.
      
      Currently, the only case where this was visible was with:
      
        $ nmcli --pretty general permissions
      
      (note that "--mode tabular" is the default).
      
      Fixes: 16299e5a
      e1bbc2e1
  13. 14 May, 2018 1 commit
    • Thomas Haller's avatar
      cli: use macro for list of argument for NmcMetaGenericInfo.get_fcn() · fc475f25
      Thomas Haller authored
      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.
      fc475f25
  14. 10 May, 2018 4 commits
    • Lubomir Rintel's avatar
      cli: use a palette to implement coloring · 31aa2cfe
      Lubomir Rintel authored
      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.
      31aa2cfe
    • Lubomir Rintel's avatar
      cli: rework enabling and disabling colors · 9dfe8258
      Lubomir Rintel authored
      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.
      9dfe8258
    • Lubomir Rintel's avatar
      cli: drop --prompt-color · 56a5b273
      Lubomir Rintel authored
      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.
      56a5b273
    • Lubomir Rintel's avatar
      all: use the elvis operator wherever possible · e69d3869
      Lubomir Rintel authored
      Coccinelle:
      
        @@
        expression a, b;
        @@
        -a ? a : b
        +a ?: b
      
      Applied with:
      
        spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .
      
      With some manual adjustments on spots that Cocci didn't catch for
      reasons unknown.
      
      Thanks to the marvelous effort of the GNU compiler developer we can now
      spare a couple of bits that could be used for more important things,
      like this commit message. Standards commitees yet have to catch up.
      e69d3869
  15. 30 Apr, 2018 1 commit
  16. 13 Apr, 2018 2 commits
  17. 07 Feb, 2018 1 commit
  18. 12 Dec, 2017 1 commit
    • Thomas Haller's avatar
      cli: drop nmc_strsplit_set() · 5d3736ac
      Thomas Haller authored
      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).
      5d3736ac
  19. 14 Nov, 2017 1 commit
  20. 30 Oct, 2017 2 commits
  21. 07 Jun, 2017 1 commit
    • Beniamino Galvani's avatar
      cli: disable pager in editor mode · ea909e38
      Beniamino Galvani authored
      nmcli closes its stdout when spawning the pager and thus, in editor
      mode, nothing is printed once the pager terminates. For an interactive
      mode like the editor, the pager seems not suitable, disable it.
      
      Fixes: 24c079e4
      ea909e38
  22. 15 May, 2017 1 commit
  23. 23 Apr, 2017 1 commit
    • Thomas Haller's avatar
      cli: don't mark field names for translation · 83a6f362
      Thomas Haller authored
      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.
      83a6f362
  24. 13 Apr, 2017 3 commits
  25. 12 Apr, 2017 1 commit
    • Thomas Haller's avatar
      cli: cleanup meta data virtual function arguments · b7efa627
      Thomas Haller authored
      - 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.
      b7efa627