code: def choose(msg, items, attr):  # pragma: no cover
      
      # Return the first item if there is only one choice
      if len(items) == 1:
          return items[0]
      # Print all choices to the command line
      print()
      for index, i in enumerate(items):
          name = attr(i) if callable(attr) else getattr(i, attr)
          print('  %s: %s' % (index, name))
      print()
      # Request choice from the user
      while True:
          try:
              inp = input('%s: ' % msg)
              if any(s in inp for s in (':', '::', '-')):
                  idx = slice(*map(lambda x: int(x.strip()) if x.strip() else None, inp.split(':')))
                  return items[idx]
              else:
                  return items[int(inp)]
  
          except (ValueError, IndexError):
              pass
docs: Command line helper to display a list of choices, asking the
          user to choose one of the options.