1. 06 Aug, 2021 2 commits
  2. 20 Jul, 2021 1 commit
  3. 13 Jul, 2021 1 commit
    • Zane Bitter's avatar
      Colourise and automatically page help output · 8fa916e9
      Zane Bitter authored
      Using the autopage library we can automatically send the help output to
      a pager (less, by default), git-style. The pager is configured to not
      reset the terminal on exit, avoiding the problem when piping to less
      manually that the help text you want to refer to disappears off the
      screen when you go to use it. The pager is only invoked when the output
      is to the terminal.
      
      Since we invoke the pager, we can ensure that it is correctly set up to
      interpret ANSI escape codes, so it is safe to use colour to make the
      output easier to read. The autopage library provides light styling of
      the default argparse help output, and some additional colour
      highlighting is added here for the command list (which is generated by
      cliff, not using argparse's formatting code).
      
      Change-Id: If9e1aa5166da32c58cc0fa617f4f81eaa9b2c470
      Depends-On: https://review.opendev.org/c/openstack/requirements/+/799343
      8fa916e9
  4. 15 Jun, 2021 1 commit
  5. 07 Jun, 2021 1 commit
    • Zane Bitter's avatar
      Handle SIGPIPE exit gracefully · 392f3b2e
      Zane Bitter authored
      If we are piping output to a command that exits before the entire
      output is written (e.g. "head") then we will receive a BrokenPipeError.
      This is expected and we should react by exiting gracefully, setting an
      appropriate return code (128 + SIGPIPE).
      
      Change-Id: I0d60e44450da1f48dbd8f459549da80fda69aad5
      392f3b2e
  6. 04 Jun, 2021 1 commit
    • matbu's avatar
      Add conflict_handler parameter as attribut in Command class · 452fff3a
      matbu authored
      Adding conflict_handler as attribut in the Command class in order to be
      able to take control of this parameter and change to different behavior
      that argparse is handling: error / resolve / ignore.
      
      Callers will be able to override it and get a proper Parser object.
      
      Change-Id: I327ece99a04bc8b2ebfa554dea643b1f2a456336
      452fff3a
  7. 14 May, 2021 1 commit
  8. 13 May, 2021 2 commits
  9. 20 Apr, 2021 1 commit
  10. 19 Mar, 2021 1 commit
  11. 11 Feb, 2021 1 commit
  12. 10 Feb, 2021 2 commits
  13. 09 Feb, 2021 2 commits
  14. 29 Jan, 2021 3 commits
    • Stephen Finucane's avatar
      Add '--sort-ascending', '--sort-descending' parameters · 7798cb2e
      Stephen Finucane authored
      
      
      Allow users to reverse sorting direction.
      
      Change-Id: Iecd539139c5a7ce4abaaee2ff5632a2459437d51
      Signed-off-by: default avatarStephen Finucane <sfinucan@redhat.com>
      7798cb2e
    • Stephen Finucane's avatar
      Make 'FormattableColumn' comparable · c1c99104
      Stephen Finucane authored
      
      
      Implement the '__lt__' magic method, thus providing the minimal set of
      rich comparison methods necessary to support sorting. This will allows
      users using these formatters for the more basic types (i.e. not dicts)
      to sort their output using the standard '--sort-column' option.
      
      Change-Id: I08e1f1bc75fa6452f19dfb9d221c1daec194d58d
      Signed-off-by: default avatarStephen Finucane <sfinucan@redhat.com>
      c1c99104
    • Stephen Finucane's avatar
      Handle null values when sorting · 4f45f9a3
      Stephen Finucane authored
      One unfortunate change (or fortunate, depending on how you look at
      types) in Python 3 is the inability to sort iterables of different
      types. For example:
      
        >>> x = ['foo', 'bar', None, 'qux']
        >>> sorted(x)
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
        TypeError: '<' not supported between instances of 'NoneType' and 'str'
      
      Fortunately, we can take advantage of the fact that by providing a
      function for the 'key' that returns a tuple, we can sort on multiple
      conditions. In this case, "when the first key returns that two elements
      are equal, the second key is used to compare." [1] We can use this to
      first separate the values by whether they are None or not, punting those
      that are not to the end, before sorting the non-None values normally.
      For example:
      
        >>> x = ['foo', 'bar', None, 'qux']
        >>> sorted(x, key=lambda k: (k is None, k))
        ['bar', 'foo', 'qux', None]
      
      We were already using this feature implicitly through our use of
      'operator.itemgetter(*indexes)', which will return a tuple if there is
      more than one item in 'indexes', and now we simply make that explicit,
      fixing the case where we're attempting to compare a comparable type
      with None. For all other cases, such as comparing a value that isn't
      comparable, we surround things with a try-catch and a debug logging
      statement to allow things to continue.
      
      Note that we could optimize what we're done further by building a key
      value that covers all indexes, rather than using a for loop to do so.
      For example:
      
        >>> x = [('baz', 2), (None, 0), ('bar', 3), ('baz', 4), ('qux', 0)]
        >>> sorted(x, key=lambda k: list(
        ...     itertools.chain((k[i] is None, k[i]) for i in (0, 1)))
        ... )
        [('bar', 3), ('baz', 2), ('baz', 4), ('qux', 0), (None, 0)]
      
      However, this would be harder to grok and would also mean we're unable
      to handle exceptions on a single column where e.g. there are mixed types
      or types that are not comparable while still sorting on the other
      columns. Perhaps this would be desirable for some users, but sorting on
      a best-effort basis does seem wiser and generally more user friendly.
      Anyone that wants to sort on such columns should ensure their types are
      comparable or implement their own sorting implementation.
      
      [1] https://www.kite.com/python/answers/how-to-sort-by-two-keys-in-python
      
      
      
      Change-Id: I4803051a6dd05c143a15923254af97e32cd39693
      Signed-off-by: default avatarStephen Finucane <sfinucan@redhat.com>
      Story: 2008456
      Task: 41466
      4f45f9a3
  15. 28 Jan, 2021 1 commit
  16. 27 Jan, 2021 2 commits
  17. 18 Nov, 2020 3 commits
  18. 09 Nov, 2020 1 commit
  19. 06 Nov, 2020 1 commit
  20. 04 Nov, 2020 1 commit
    • Stephen Finucane's avatar
      columns: Make 'FormattableColumn' comparable · 997e05fc
      Stephen Finucane authored
      
      
      Currently, comparing instances of this fails:
      
        >>> from cliff.columns import FormattableColumn
        >>> class Test(FormattableColumn):
        ...     def human_readable(self):
        ...         return str(self._data)
        ...
        >>> data = {'x': 'y'}
        >>> x = Test(data)
        >>> y = Test(data)
        >>> x == y
        False
      
      Clearly it should not. Resolve this by implementing a custom comparison.
      
      Change-Id: I4b96475ca6a689f4055dc5ea34b82b3867a65555
      Signed-off-by: default avatarStephen Finucane <sfinucan@redhat.com>
      Story: #2008320
      Task: #41218
      997e05fc
  21. 30 Oct, 2020 1 commit
    • likui's avatar
      Update requirements URLs in tox config · f05d554e
      likui authored
      Update the URL to the upper-constraints file to point to the redirect
      rule on releases.openstack.org so will switch to the correct
      upper-constraints list automatically when the requirements repository branches.
      
      Change-Id: Ia69a02b539230e65e25da65d5d76a9f650490256
      f05d554e
  22. 29 Oct, 2020 4 commits
  23. 23 Oct, 2020 1 commit
  24. 22 Oct, 2020 1 commit
  25. 19 Oct, 2020 1 commit
  26. 13 Oct, 2020 1 commit
  27. 06 Oct, 2020 1 commit
  28. 01 Oct, 2020 1 commit